Silverlight 4自定义控件子项风格

时间:2010-10-12 18:24:37

标签: c# .net silverlight

我有自定义控件,我想显示一些项目。 在generic.xaml定义的自定义控件样式中:

  <Style TargetType="local:Custom">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:Customl">
                <!-- Root Grid-->
                <Grid x:Name="CustomLayout"
                      Background="Black">
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我设置为C#

  [TemplatePart(Name = "CustomLayout", Type = typeof(Grid))]
[StyleTypedProperty(Property = "ChildItemStyle", StyleTargetType = typeof(Control))]
public class GaugeControl : Control

除了童装款式外,一切工作正常 定义于 generic.xaml:

  <Style TargetType="{x:Type Control}">
    <Setter Property="Background" Value="Red"></Setter>
        <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Control}">
                <!-- Root Grid-->
                <Grid x:Name="LayoutRoot"
                      Background="Red">
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

具有属性

的自定义控件
 [StyleTypedProperty(Property = "ChildItemStyle", StyleTargetType = typeof(Control))]

我的自定义控件中有ChildItemStyle DependencyProperty,但它始终为null。

我如何获得这个Style属性,我正在做什么错误?

1 个答案:

答案 0 :(得分:0)

我在代码中找到了解决方案和错误。

我只是将setter添加到我的<Style TargetType="local:Custom">定义中,并在我想要的setter set ChildItemStyle的帮助下添加。

相关问题