我为GroupBoxes的标题定义了一个DataTemplate:
<Style x:Key="GroupBoxHeaderStyle" TargetType="{x:Type GroupBox}">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}"
FontSize="18" FontFamily="Global User Interface"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
然而,为前景进行的绑定似乎不起作用。我的groupBoxes的标题总是黑色的。我究竟做错了什么?
这就是我定义GroupBox的方式:
<GroupBox Header="Views" Margin="1" Foreground="White"
Style="{StaticResource GroupBoxHeaderStyle}">
...
答案 0 :(得分:3)
...
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Foreground}"
FontSize="18" FontFamily="Global User Interface"/>
...