내 UserControl에는 여러 개의 레이블이 있습니다. XAML에서 나는 클라이언트가 이들 모두를 위해 Foreground를 한 번에 설정할 수있는 설정기를 정의하려고합니다.XAML을 사용하여 UserControl의 모든 요소에 대한 전경색 설정 도구를 추가하십시오.
소스 코드 : (간체) Page.Resources에서
: 페이지의 내용에
<DataTemplate x:Key="customItemTemplate">
<StackPanel Orientation="Horizontal">
<MyControlLib:XYControl Unit="{Binding XYUnit}"/>
<TextBlock Text="{Binding XYMultiplier}" Width="16"/>
</StackPanel>
</DataTemplate>
:
<ListBox x:Name="XYZList" ItemTemplate="{StaticResource customItemTemplate}">
<!-- Set Foreground to "Red" for all items -->
<!-- For XYControl this is the TextForeground property -->
<!-- For TextBlock this is (naturally) the Foreground property -->
</ListBox>
합니다 (WPF의 XAML 코멘트를 읽기 위대함을 달성하고 싶다)
물론 customItemTemplate
은 페이지에서 한 곳 이상에서 다른 색으로 사용됩니다.
WPF에서 얼마나 간단할까요?