开发者

WPF 2 Grid - hide 1 and the other should expand

I have the following form.

WPF 2 Grid - hide 1 and the other should expand

These rows reside in a Grid and the darker blue areas, section 1 and section 2, are Grids themselves.

How do I have Grid 2 expand and fill the row when Grid 1 has been collapsed? I attempted a StackPanel 开发者_运维知识库but that only moved Grid 2 up and left it the same size.

I'd like it to look like this when Grid 1 has been collapsed:

WPF 2 Grid - hide 1 and the other should expand

Any suggestions on how to do this?

Thanks again!


You need to make sure Grid2 is set up to fill the available space. If you have one Grid that contains Grid1, Grid2, and everything else, just make sure the RowHeight for the row containing Grid2 is set to * and everything else set to auto:

<Grid Name="MainGrid">
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="auto"/>
    </Grid.RowDefinitions>
    <Grid Name="Grid1" Grid.Row="0"/>
    <Grid Name="Grid2" Grid.Row="1"/>
    <Grid Name="EverythingBelow" Grid.Row="2"/>
<Grid>


Turn on/off the Visibility="Collapsed" with this XAML

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Background="Red" Visibility="Collapsed" >
        <TextBlock Height="50" Text="Grid1" />
    </Grid>

    <Grid Grid.Row="1" Background="Yellow">
        <TextBlock Text="Grid2" />
    </Grid>

</Grid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜