Проблемы с привязкой свойства Foreground GroupBox HeaderTemplate - PullRequest
1 голос
/ 09 июня 2009

Я определил DataTemplate для заголовка моего GroupBoxes:

   <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>

Однако привязка к переднему плану, похоже, не работает. Заголовки моей группы Boxes всегда черные. Что я делаю неправильно?

Вот как я определяю GroupBox:

<GroupBox Header="Views" Margin="1" Foreground="White"
          Style="{StaticResource GroupBoxHeaderStyle}">
          ...

1 Ответ

3 голосов
/ 09 июня 2009
...
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Foreground}"
           FontSize="18" FontFamily="Global User Interface"/>
...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...