【问题标题】:WPF grid expander listview fills up the space when gridsplitter moves当gridsplitter移动时,WPF网格扩展器列表视图会填满空间
【发布时间】:2016-10-08 23:28:07
【问题描述】:

我有以下 .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 个带网格分割器的扩展器。我想实现以下两点:

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

(2) 每当一个 gridsplitter 移动时,2 个扩展器会自动调整它们的高度以填满空间。

该行为应类似于 Windows 资源管理器概述窗口的行为。任何建议和见解表示赞赏

【问题讨论】:

标签: wpf resize expander gridsplitter


【解决方案1】:

看看这是不是你需要的:

<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;
}

【讨论】:

    猜你喜欢
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-07
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多