Change background color of header in WPF expander
Asked Answered
G

1

5

I am trying to change the expander background color. 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 doesn't HorizontalAlignment="Stretch" help? I am trying to bind the width of Header to the width of Expander but the result is not nice looking.

Gentilesse answered 20/5, 2009 at 14:15 Comment(0)
S
14

here you go, this should do the trick.... You should 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>
Superannuation answered 20/5, 2009 at 14:33 Comment(3)
Good answer, but i tried that allready, it doesn't help, it seems that the header becomes bigger than expanderGentilesse
funny, worked fine for me--should be exactly the same width. you could make a converter that takes the width and subtracts some amount from it, returning the result.Fairly
This doesnt work all the time - especially when Expander's width is not pre-set. I used the trick to set the width to another parent component whose width will not change.Suture

© 2022 - 2024 — McMap. All rights reserved.