How can I make a WPF Expander Stretch?


Question

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

1
31
9/11/2013 2:10:48 AM

Accepted Answer

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/

44
5/4/2016 1:40:06 PM

Non stretchable Expanders is usually the problem of non stretchable parent controls.. Perhaps one of the parent controls has defined a HorizontalAlignment or VerticalAlignment property?

If you can post some sample code, we can give you a better answer.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon