如何让内容围绕扩展/折叠WPF扩展器进行重新调整?

时间:2022-08-19 21:38:57

Right now I have a Stackpanel, that contains a collapsed Expander, and a Listbox.

现在我有一个Stackpanel,它包含一个折叠的Expander和一个Listbox。

The Listbox beneath the collapsed Expander is being positioned as if the Expander was expanded. Is it possible for the StackPanel to dynamically do layout based on the collapsed size of the Expander, and then on the Expanded size of the Expander once it's been clicked on?

折叠扩展器下方的列表框的位置就像展开扩展器一样。 StackPanel是否可以根据Expander的折叠大小动态进行布局,然后在点击后展开扩展的扩展大小?

Thanks for your help.

谢谢你的帮助。

1 个解决方案

#1


After a bunch of documentation reading, I determined what my problem was.

经过一堆文档阅读后,我确定了我的问题。

If you explicitly set the height of the Expander (in a vertical layout) then it will always use that size in a StackPanel. If you set the height to "Auto" then it will use the contents of the Expander for the expanded size, and the collapsed size of the Expander when it's collapsed.

如果您明确设置Expander的高度(在垂直布局中),那么它将始终在StackPanel中使用该大小。如果将高度设置为“自动”,则它将使用扩展器的内容作为扩展大小,以及扩展器在折叠时的折叠大小。

#1


After a bunch of documentation reading, I determined what my problem was.

经过一堆文档阅读后,我确定了我的问题。

If you explicitly set the height of the Expander (in a vertical layout) then it will always use that size in a StackPanel. If you set the height to "Auto" then it will use the contents of the Expander for the expanded size, and the collapsed size of the Expander when it's collapsed.

如果您明确设置Expander的高度(在垂直布局中),那么它将始终在StackPanel中使用该大小。如果将高度设置为“自动”,则它将使用扩展器的内容作为扩展大小,以及扩展器在折叠时的折叠大小。