我有自定义控件,可以在其中显示一些项目。
在为自定义控件定义的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
一切正常,除了儿童用品的款式
定义在
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,但它始终为空。
我怎样才能得到这个样式的属性,我做错了什么?