Changing the background color of the header in the WPF Extender

I am trying to change the background color of the expander. It seems so easy, but I can't get it to work.

<Expander Name="expOneDay">
        <Expander.Header>
            <TextBlock Foreground="CadetBlue" Text="Some Text" HorizontalAlignment="Stretch" />
        </Expander.Header>
 ...

</Expander><br/><br/>

Why HorizontalAlignment="Stretch"doesn’t it help? I am trying to snap width Headerto width Expander, but the result does not look nice.

+3
source share
1 answer

here you go, this should do the trick .... You need to set the width of the header template to the width of the expander.

<Expander Name="expOneDay" 
          HorizontalAlignment="Stretch"
          HorizontalContentAlignment="Stretch" Width="Auto">
     <Expander.Header >
          <Border Background="Bisque">
               <TextBlock Foreground="White" Text="Steve" 
                          Width="{Binding ElementName=expOneDay, Path=ActualWidth}"
                          HorizontalAlignment="Stretch" />
          </Border>
     </Expander.Header>
</Expander>
+9
source

Source: https://habr.com/ru/post/1708739/


All Articles