我为我的GroupBox的标题定义了一个数据表板:

   <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"/>
...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top