0
스타일을 종속 속성으로 표시하려고합니다. 기본적으로 중간에 사각형 표시기가 있으며 사용하는 컨트롤은 설정할 컨트롤을 포함하는 스타일 종속성 속성을 노출합니다. 그것은 컨트롤을 포함하는 사람들이 아이템에 대한 자신의 지식을 기반으로 채색 스타일을 제공 할 수있게합니다.스타일 속성 유형의 종속성 속성
<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>
이 전혀 작동하지 않는 나의 접근 방식도 맞는지 잘 모르겠어요 :
public Style RectangleStyle
{
get { return (Style)GetValue(RectangleStyleProperty); }
set { SetValue(RectangleStyleProperty, value); }
}
public static readonly DependencyProperty RectangleStyleProperty =
DependencyProperty.Register("RectangleStyle", typeof(Style), typeof(MyControl), new PropertyMetadata(null));
이
은 다음과 같이 사용됩니다.