当gridsplitter移动时,WPF网格扩展器列表视图填满空间

时间:2016-10-07 12:24:15

标签: wpf resize expander gridsplitter

我有以下内容.XAML:

NSString *s = parsedMessageDict[@"s"]; //ZB3NNxAMNB/x6JpAryCd0g==
NSData *salt = [[NSData alloc] initWithBase64EncodedString:s options:0];

有2个带有栅格分离器的扩展器。我想实现以下两件事:

(1)每当一个膨胀机坍塌时,另一个膨胀机应填满空间

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

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

1 个答案:

答案 0 :(得分:0)

看看你是否需要:

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