WPF 嵌套容器

发布于 2024-10-09 13:29:46 字数 249 浏览 0 评论 0原文

在窗口控件上,我的主要容器是网格。
我的网格有 2 行,一行定义为 50*,另一行定义为 250*。
现在我想添加一个右侧边栏,比如说使用 StackPanel。
我希望 StackPanel 中有一个与 50* 网格行对齐的 ListBox,因此随着窗口高度变大,ListBox 的大小也会变大。
我的问题是,当 ListBox 位于 StackPanel(嵌套在网格内)内部时,我是否可以实现此行为,或者必须将 ListBox 直接放置在网格内?

On a window control, my main container is a grid.
My grid has 2 rows, one row definition is 50*, and the other is 250*.
Now i want to add a right sidebar, lets say with a StackPanel.
I would like to have a ListBox inside the StackPanel that aligns with the 50* grid row, so as the window height gets bigger, the ListBox size will also get bigger.
My question is whether i can achieve this behavior while the ListBox is inside the StackPanel (which is nested inside the grid) or must the ListBox be placed directly inside the grid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亢潮 2024-10-16 13:29:46

StackPanel 不会垂直拉伸。

如果您必须需要一个包装父容器,请使用 Grid,它将向各个方向扩展(当然,如果您不考虑水平和垂直对齐;))

还请查看 面板概述

Panel Name       x-Dimension             y-Dimension


- Canvas         Constrained to content     Constrained to content
- DockPanel      Constrained             Constrained
- StackPanel     Constrained             Constrained to content
  (Vertical Orientation)    
- StackPanel     Constrained to content  Constrained 
  (Horizontal Orientation)  
- Grid        Constrained             Constrained, except in cases where Auto apply to rows and columns
- WrapPanel      Constrained to content  Constrained to content

StackPanel does not stretch vertically.

If you must need a wrapping parent container, use a Grid, which will expand in all directions (if you leave the Horizontal- and VerticalAlignment alone of course ;) )

Also check out the Panel Overview on MSDN.

Panel Name       x-Dimension             y-Dimension


- Canvas         Constrained to content     Constrained to content
- DockPanel      Constrained             Constrained
- StackPanel     Constrained             Constrained to content
  (Vertical Orientation)    
- StackPanel     Constrained to content  Constrained 
  (Horizontal Orientation)  
- Grid        Constrained             Constrained, except in cases where Auto apply to rows and columns
- WrapPanel      Constrained to content  Constrained to content
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文