简体   繁体   English

删除用户控件时,WPF Stackpanel 高度未调整大小

[英]WPF Stackpanel height not resizing when removing a usercontrol

I have a stackpanel in a grid row with the row height set to auto.我在网格行中有一个堆栈面板,行高设置为自动。

I add user controls at runtime and the height resizes fine, when removing the user controls the height does not reduce though.我在运行时添加用户控件并且高度调整大小,但在删除用户控件时高度不会降低。 I have tried to clear the stackpanel children, remove them one by one and also implemented IDisposable in each user control but when the child count shows zero the height has not reduced.我试图清除堆栈面板子项,将它们一个一个地删除,并在每个用户控件中实现IDisposable但是当子项计数显示为零时,高度并没有减少。

Sample XAML below, any help would be welcomed please?下面的示例 XAML,欢迎任何帮助吗?

<Grid x:Name="TestGrid">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Test Header" Style="{StaticResource SubHeaderTextBlock}" />
    </StackPanel>
    <StackPanel x:Name="ChildItems" Grid.Row="1" />
</Grid>

Replace the StackPanel with a Grid.Grid.替换StackPanel Grid. Grids stretch and retract better than StackPanels.网格比 StackPanels 更好地伸缩。

已删除放置Visibility Collapsed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM