C# Silverlight 4自定义控件子项样式
我有一个自定义控件,我想在其中显示一些项目。 在自定义控件的generic.xaml定义样式中:C# Silverlight 4自定义控件子项样式,c#,.net,silverlight,C#,.net,Silverlight,我有一个自定义控件,我想在其中显示一些项目。 在自定义控件的generic.xaml定义样式中: <Style TargetType="local:Custom"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="local:Customl"> <!-- Root
<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>
除儿童用品外,一切正常
定义于
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>
我的自定义控件中有ChildItemStyle DependencyProperty,但它始终为null
如何获取此样式属性以及我的错误是什么?我在代码中找到了解决方案和错误
我只是将setter添加到我的
定义中,并借助于我想要的setter set ChildItemStyle。您使用silverlight,对吗?您是否尝试过使用TargetType=“Control”而不是x:Type…?是的,我尝试过,但错误在于我在generic.xaml中使用了separet样式,而不是使用setter为local:Custom设置一个样式,将样式设置为ChildItemStyle
<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))]