GroupBoxのHeaderTemplateのForegroundプロパティをバインドの問題
-
12-09-2019 - |
質問
私は私のグループボックスのヘッダーのための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