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>