Pregunta

He definido una DataTemplate para la cabecera de mis 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>

Sin embargo, la unión de hecho para el primer plano no parece funcionar. Las cabeceras de mis groupBoxes son siempre de color negro. ¿Qué estoy haciendo mal?

Esta es la forma en que estoy definiendo GroupBox:

<GroupBox Header="Views" Margin="1" Foreground="White"
          Style="{StaticResource GroupBoxHeaderStyle}">
          ...
¿Fue útil?

Solución

...
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Foreground}"
           FontSize="18" FontFamily="Global User Interface"/>
...
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top