GroupBox HeaderTemplate의 전경 속성을 바인딩하는 문제
-
12-09-2019 - |
문제
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>
그러나 전경에 대한 바인딩은 작동하지 않는 것 같습니다. 내 그룹 박스의 헤더는 항상 검은 색입니다. 내가 뭘 잘못하고 있죠?
이것이 제가 그룹 박스를 정의하는 방법입니다.
<GroupBox Header="Views" Margin="1" Foreground="White"
Style="{StaticResource GroupBoxHeaderStyle}">
...
해결책
...
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Foreground}"
FontSize="18" FontFamily="Global User Interface"/>
...
제휴하지 않습니다 StackOverflow