WPF Groupbox height needs to change dynamically?

这一生的挚爱 提交于 2020-01-04 01:44:20

问题


I am working with a groupbox in WPF, and Inside of the groupbox is a stackpanel. The stackpanel has items that are removed, and added to its children.

The problem I am experiencing is that Stackpanel within the groupbox is changing height, but the GroupBox is not, and so it is cutting off the rest of the added items within in the stackpanel.

How can I get the groupbox to adjust its height to the height of the stackpanel.

This must be done in code, not in XAML


回答1:


Try setting the HorizontalAlignment and VerticalAlignment of the StackPanel to Stretch and ensure that the StackPanel doesn't have explicit Width and Height set.

<StackPanel x:Name="stackPanel1" HorizontalAlignment="Stretch" VerticalAlignment="Strech">
...
</StackPanel>

or in code:

stackPanel1.HorizontalAlignment = HorzontalAlignment.Stretch;
stackPanel1.VerticalAlignment = VerticalAlignment.Stretch;

Paste your code/xaml to help us make lesser assumptions.



来源:https://stackoverflow.com/questions/5722234/wpf-groupbox-height-needs-to-change-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!