折叠堆栈面板时从网格中删除空间

问题描述 投票:0回答:1

我有一个应用程序,我在网格中显示堆栈面板行。用户可以隐藏堆栈面板的行以“清理”网格,并且只查看/编辑他们想要的内容,其目的是折叠分隔符之间的堆栈面板和关闭之间的空间。

当我将stackpanel设置为Visibility.Collapsed时,stackpanel消失但它们占用的空间仍然存在。

如何消除差距? (我添加了updatelayout,但这似乎没有做任何事情)

它之前的样子:Before

之后的样子:After

我的XAML:

    <ScrollViewer Name="scroll" PanningMode="Both" Grid.Column="0" Grid.Row="1">
        <ScrollViewer.Resources>
            <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarWidthKey}">50</sys:Double>
            <sys:Double x:Key="{x:Static SystemParameters.VerticalScrollBarButtonHeightKey}">50</sys:Double>
        </ScrollViewer.Resources>
        <Grid x:Name="RecipeEditorCtrl" VerticalAlignment="Top">                
        </Grid>
    </ScrollViewer>

我的C#:

        ...
        int rowIndex = Grid.GetRow(CNtmp);

        rowIndex++;
        tmpCN = (CollectionNode)RecipeEditorCtrl.Children[rowIndex];
        while (tmpCN.dataType.Text != "SEPERATOR")
        {
            tmpCN.Visibility = Visibility.Collapsed;
            rowIndex++;
            tmpCN = (CollectionNode)RecipeEditorCtrl.Children[rowIndex];
        }
        RecipeEditorCtrl.UpdateLayout();
    }
c# wpf xaml grid
1个回答
1
投票

你可以使用RowsDefinitions并将每个RowDefinition Height属性添加到Auto然后将你的StackPanel添加到那些行

© www.soinside.com 2019 - 2024. All rights reserved.