Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Silverlight 4自定义控件子项样式_C#_.net_Silverlight - Fatal编程技术网

C# Silverlight 4自定义控件子项样式

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

我有一个自定义控件,我想在其中显示一些项目。 在自定义控件的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>
除儿童用品外,一切正常 定义于 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))]