1

我为我的 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}">
          ...
4

1 回答 1

3
...
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Foreground}"
           FontSize="18" FontFamily="Global User Interface"/>
...
于 2009-06-08T23:46:35.870 回答