I have custom control where i want to show some items. In generic.xaml defined style for custom control:
<Style TargetType="local:Custom">
<Setter Property="Template">
<Setter.Value&开发者_开发知识库gt;
<ControlTemplate TargetType="local:Customl">
<!-- Root Grid-->
<Grid x:Name="CustomLayout"
Background="Black">
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And i set to C#
[TemplatePart(Name = "CustomLayout", Type = typeof(Grid))]
[StyleTypedProperty(Property = "ChildItemStyle", StyleTargetType = typeof(Control))]
public class GaugeControl : Control
Everything working fine excepts style for child items defined in 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>
Custom control with attribute
[StyleTypedProperty(Property = "ChildItemStyle", StyleTargetType = typeof(Control))]
And i have ChildItemStyle DependencyProperty in my custom control but its always null.
How can i get this Style property and whats wrong i am doing?
I found solution and bug in my code.
I just add setter to my <Style TargetType="local:Custom">
definition and with help of setter set ChildItemStyle which i want.
精彩评论