Question

Je défini un DataTemplate pour l'en-tête de mes boîtes de groupes:

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

Cependant la liaison fait pour le premier plan ne semble pas fonctionner. Les en-têtes de mes sont toujours noirs boîtes de groupes. Qu'est-ce que je fais mal?

Voici comment je définir GroupBox:

<GroupBox Header="Views" Margin="1" Foreground="White"
          Style="{StaticResource GroupBoxHeaderStyle}">
          ...
Était-ce utile?

La solution

...
<TextBlock Text="{Binding}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}}, Path=Foreground}"
           FontSize="18" FontFamily="Global User Interface"/>
...
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top