这是WPF GroupBox的样式。 我能够从App.xaml.cs中定义的属性设置Groupbox背景和Groupbox边框颜色的值,如图所示。
<Style x:Key="StyleGroupBox1" TargetType="GroupBox">
<Setter Property="Background" >
<Setter.Value>
<Binding Path="GroupBox_Background" Source="{x:Static Application.Current}"/>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>
<Binding Path="Groupbox_BorderColor" Source="{x:Static Application.Current}"/>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="1,1,1,1"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" FontWeight="Bold" FontFamily="Palatino Linotype" FontSize="17" Foreground="DarkRed" FontStyle="Italic">
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
如何设置GroupBox的标题模板的ForeGround类似于我设置Groupbox的背景和bordercolor的方式(即从我的app.xaml.cs中定义的属性)?即当前标题文本已设置到DarkRed,但是如何使用App.xaml.cs中的属性设置它?
答案 0 :(得分:1)
<TextBlock
Text="{Binding}"
FontWeight="Bold"
FontFamily="Palatino Linotype"
FontSize="17"
Foreground="{Binding Source={x:Static Application.Current}, Path=Groupbox_HeaderForegroundColor}"
FontStyle="Italic">