C# 支持模板的Windows phone自定义用户控件

C# 支持模板的Windows phone自定义用户控件,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我正在创建一个自定义用户控件,我希望该控件可以重用,并且该控件的一部分可以用于添加新控件。我试图在自定义用户控件中创建一个模板,用户可以在其中添加新内容 我正在使用WindowsPhone8 如何执行此操作?从“添加新项”菜单添加新模板控件。 您应该在Themes文件夹中获得Generic.xaml文件 在Generic.xaml中,您拥有自定义控件的样式: <Style TargetType="local:CustomControl1"> <Setter Proper

我正在创建一个自定义用户控件,我希望该控件可以重用,并且该控件的一部分可以用于添加新控件。我试图在自定义用户控件中创建一个模板,用户可以在其中添加新内容

我正在使用WindowsPhone8


如何执行此操作?

从“添加新项”菜单添加新模板控件。 您应该在
Themes
文件夹中获得
Generic.xaml
文件

Generic.xaml
中,您拥有自定义控件的样式:

<Style TargetType="local:CustomControl1">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:CustomControl1">
                Write your control xaml here
                <Border x:Name="BorderNameTest"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                    <Button IsEnabled="{TemplateBinding IsFancyLookEnabled}"></Button>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

此外,我还向您展示了如何公开控件上的属性(以便控件用户可以编写
)。您可以创建依赖属性(如代码片段中所示),通过
模板绑定可以在xaml中使用该属性,也可以仅在代码中使用。

从“添加新项”菜单添加新模板控件。 您应该在
Themes
文件夹中获得
Generic.xaml
文件

Generic.xaml
中,您拥有自定义控件的样式:

<Style TargetType="local:CustomControl1">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:CustomControl1">
                Write your control xaml here
                <Border x:Name="BorderNameTest"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}">
                    <Button IsEnabled="{TemplateBinding IsFancyLookEnabled}"></Button>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
此外,我还向您展示了如何公开控件上的属性(以便控件用户可以编写
)。您可以创建依赖属性(如代码片段中所示),通过
模板绑定在xaml中使用该属性,或者只在代码中使用