Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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
Wpf 样式类型的依赖属性_Wpf_Wpf Controls_Dependency Properties - Fatal编程技术网

Wpf 样式类型的依赖属性

Wpf 样式类型的依赖属性,wpf,wpf-controls,dependency-properties,Wpf,Wpf Controls,Dependency Properties,我想公开一个样式作为依赖属性。基本上在中间有一个矩形指示器,使用控件将公开一个样式依赖属性,用于包含要设置的控件。它将允许那些包含控件的人根据自己对项目的了解提供一种着色样式 <ItemsControl ItemsSource="{Binding Rows}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizont

我想公开一个样式作为依赖属性。基本上在中间有一个矩形指示器,使用控件将公开一个样式依赖属性,用于包含要设置的控件。它将允许那些包含控件的人根据自己对项目的了解提供一种着色样式

<ItemsControl ItemsSource="{Binding Rows}">
   <ItemsControl.ItemTemplate>
       <DataTemplate>
           <StackPanel Orientation="Horizontal">
               <TextBlock Text="{Binding RowName}"/>
               <ItemsControl ItemsSource="{Binding Statuses}">

                    <Rectangle Style="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Path=RectangleStyle}"/>
               </ItemsControl>
           </StackPanel>
       </DataTemplate>
   </ItemsControl.ItemTemplate>
</ItemsControl>
然后将使用如下方式:

    <MyControl>
        <MyControl.RectangleStyle>
            <Style TargetType="{x:Type Rectangle}">
                <Setter Property="Fill" Value="Red"/>
            </Style>
        </MyControl.RectangleStyle>
    </MyControl>

这根本不起作用,我也不确定我的方法是否正确。

愚蠢的语法错误。我需要为内部ItemsControl设置ItemsTemplate。我正在将ItemsControl的内容设置为矩形

<ItemsControl ItemsSource="{Binding Rows}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding RowName}"/>
                <ItemsControl ItemsSource="{Binding Statuses}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Rectangle Style="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Path=RectangleStyle}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl ItemsSource="{Binding Rows}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding RowName}"/>
                <ItemsControl ItemsSource="{Binding Statuses}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Rectangle Style="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}, Path=RectangleStyle}"/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>