wpf棱镜和自定义控件

时间:2017-10-31 12:24:59

标签: wpf controls prism

我需要有关创建自定义控件和棱镜库的帮助。

自定义控件必须有两列。并使用我想要的棱镜库 在区域中插入一些视图

我有什么:

public class MyContentControl : Control
{
    public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object),
            typeof(MyContentControl), null);

    [Bindable(true)]
    public object Content
    {
        get { return GetValue(ContentProperty); }
        set { SetValue(ContentProperty, value); }
    }

    public static readonly DependencyProperty Content2Property = DependencyProperty.Register("Content2", typeof(object),
        typeof(MyContentControl), null);

    [Bindable(true)]
    public object Content2
    {
        get { return GetValue(Content2Property); }
        set { SetValue(Content2Property, value); }
    }
}

和ResoureDictionary

<Style TargetType="{x:Type local:MyContentControl}">
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:MyContentControl}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                  <ColumnDefinition/>
                                  <ColumnDefinition/>
                            </Grid.ColumnDefinition>
                            <ContentControl Grid.Column="0" Content="{TemplateBinding Content}"                                                  
                                              HorizontalAlignment="Center"
                                              VerticalAlignment="Center"
                                            Background="IndianRed"/>
                            <ContentControl Grid.Column=1  Content="{TemplateBinding Content2}"
                                             HorizontalAlignment="Center"
                                              VerticalAlignment="Center"
                                            Background="Aqua" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

我想要的是像

一样使用它
<MyContentControl>
     <MyContentControl.Content1>
           <ContentControl prism:RegionManager.RegionName="{x:Static constants:RegionNames.Content1_Region}"/>
     </MyContentControl.Content1>
     <MyContentControl.Content2>
           <ContentControl prism:RegionManager.RegionName="{x:Static constants:RegionNames.Content2_Region}"/>
     </MyContentControl.Content2>
</MyContentControl >

0 个答案:

没有答案