WPF网格扩展器列表视图在gridsplitter移动时填满了空间 [英] WPF grid expander listview fills up the space when gridsplitter moves

查看:209
本文介绍了WPF网格扩展器列表视图在gridsplitter移动时填满了空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下.XAML:

<Grid>
<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Expander Grid.Row="0">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="5"/>
        </Grid.RowDefinitions>
        <ListView Grid.Row="0"/>
        <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5"/>
   </Grid>
</Expander>
<Expander Grid.Row="1">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="5"/>
        </Grid.RowDefinitions>
        <ListView Grid.Row="0"/>
        <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5"/>
   </Grid>
</Expander>

有2个带网格分割器的扩展器.我想实现以下两件事:

There are 2 expanders with gridsplitters. I want to achieve the following 2 things:

(1)每当一个扩展器崩溃时,另一扩展器应填满该空间

(1) Whenever one expander collapses, the other expander should fill up the space

(2)每当一个网格拆分器移动时,两个扩展器就会自动调整其高度以填满空间.

(2) Whenever one gridsplitter moves, the 2 expanders automatically adjusts their heights to fill up the space.

该行为应类似于"Windows资源管理器概述"窗口的行为.任何建议和见解都将受到赞赏

The behavior is expected to be similar to the Windows Resource Manager Overview window's behavior. Any advice and insight is appreciated

推荐答案

看看这是否是您需要的:

See if this is what you need :

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

    <Expander Grid.Row="0" Collapsed="Expander_Collapsed_1">
        <ListView x:Name="Lv1"/>
    </Expander>
    <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5" Background="#FFB82424"/>

    <Expander Grid.Row="2" Collapsed="Expander_Collapsed_1">
        <ListView x:Name="Lv2" Grid.Row="0"/>          
    </Expander>
    <GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5" Background="#FFC51A1A"/>
</Grid>
</Window>

代码:

private void Expander_Collapsed_1(object sender, RoutedEventArgs e)
{
    DependencyObject dobj = VisualTreeHelper.GetParent(sender as Expander);
    while (!(dobj is Grid))
        dobj = VisualTreeHelper.GetParent(dobj);

    int i = Grid.GetRow(sender as Expander);
    Grid grd = dobj as Grid;
    grd.RowDefinitions[i].Height = GridLength.Auto;
}

这篇关于WPF网格扩展器列表视图在gridsplitter移动时填满了空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆