Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid and two columns in it.. I place an expander in the second column... based on expanding or collapsing it, the width of the first column should vary. To be more specific, the contents in the first grid should occupy the whole window when the expander is in collapsed state and when expanded, the first column width should get adjusted to give space for the contents in the expander


XML
<Window x:Class="GridSplitterExample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Width="1200">
    <Grid Style="{DynamicResource BaseGridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="900"/>
            <ColumnDefinition Width="300"/>
        </Grid.ColumnDefinitions>
        <Grid Width="1100">
            <GroupBox Header="Variable section" Width="1100"/>
        </Grid>
        <Grid Grid.Column="2">
            <Expander  ExpandDirection="Left" ToolTip="Show/Hide TaskPanel">
                <GroupBox Header="Expander section" Width="300"/>
            </Expander>
        </Grid>
    </Grid>
</Window>


The size of the contents in the groupbox also should occupy the whole window if expander is collapsed and shrink if expander is expanded
Posted
Updated 4-Nov-11 1:29am
v2

1 solution

Just use "*" in the width (instead of the hardcoded 900 value).
Make the 300 width "Auto".

Try
<columndefinition width="*" />
<columndefinition width="Auto" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900