How can I make a WPF Expander Stretch?

coder_bro picture coder_bro · Mar 25, 2009 · Viewed 36.1k times · Source

The Expander control in WPF does not stretch to fill all the available space. Is there any solutions in XAML for this?

Answer

Jonathan Parker picture Jonathan Parker · Mar 25, 2009

All you need to do is this:

<Expander>
  <Expander.Header>
    <TextBlock
      Text="I am header text..."
      Background="Blue"
      Width="{Binding
        RelativeSource={RelativeSource
          Mode=FindAncestor,
          AncestorType={x:Type Expander}},
        Path=ActualWidth}"
      />
  </Expander.Header>
  <TextBlock Background="Red">
    I am some content...
  </TextBlock>
</Expander>

http://joshsmithonwpf.wordpress.com/2007/02/24/stretching-content-in-an-expander-header/