Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of header in WPF expander

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.

like image 512
Arsen Mkrtchyan Avatar asked Dec 23 '22 11:12

Arsen Mkrtchyan


1 Answers

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>
like image 110
Muad'Dib Avatar answered Jan 02 '23 19:01

Muad'Dib