How can I make a WPF Expander Stretch?
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/
Non stretchable Expander
s 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.
This solution is a lot simpler and does not effect other expander controls you may using in your application.
<Expander ExpandDirection="Right" Grid.Column="0" Name="topOfB"> <Expander.Header> <Grid HorizontalAlignment="Stretch" Width="{Binding Path=ActualWidth, ElementName=topOfB}"> <!-- control content goes here -->