问题:
Some WPF controls (like the Button
) seem to happily consume all the available space in its' container if you don't specify the height it is to have.如果您没有指定它的高度,一些 WPF 控件(如Button
)似乎很乐意消耗其容器中的所有可用空间。
And some, like the ones I need to use right now, the (multiline) TextBox
and the ListBox
seem more worried about just taking the space necessary to fit their contents, and no more.还有一些,比如我现在需要使用的那些,(多行) TextBox
和ListBox
似乎更担心只占用适合其内容所需的空间,仅此ListBox
。
If you put these guys in a cell in a UniformGrid
, they will expand to fit the available space.如果您将这些家伙放在UniformGrid
一个单元格中,它们将扩展以适应可用空间。 However, UniformGrid
instances are not right for all situations.然而, UniformGrid
实例并不适合所有情况。 What if you have a grid with some rows set to a * height to divide the height between itself and other * rows?如果您有一个网格,其中一些行设置为 * 高度以划分其自身和其他 * 行之间的高度,该怎么办? What if you have a StackPanel
and you have a Label
, a List
and a Button
, how can you get the list to take up all the space not eaten by the label and the button?如果你有一个StackPanel
并且你有一个Label
,一个List
和一个Button
,你怎么能让列表占据标签和按钮没有占用的所有空间?
I would think this would really be a basic layout requirement, but I can't figure out how to get them to fill the space that they could (putting them in a DockPanel
and setting it to fill also doesn't work, it seems, since the DockPanel
only takes up the space needed by its' subcontrols).我认为这真的是一个基本的布局要求,但我不知道如何让它们填充它们可以填充的空间(将它们放在DockPanel
并将其设置为填充也不起作用,似乎,因为DockPanel
只占用其子控件所需的空间)。
A resizable GUI would be quite horrible if you had to play with Height
, Width
, MinHeight
, MinWidth
etc.如果您必须使用Height
、 Width
、 MinHeight
、 MinWidth
等, MinHeight
调整大小的 GUI 会非常糟糕。
Can you bind your Height
and Width
properties to the grid cell you occupy?你能将你的Height
和Width
属性绑定到你占据的网格单元吗? Or is there another way to do this?或者有另一种方法可以做到这一点?
解决方案:
参考一: https://stackoom.com/question/9OO参考二: How to get controls in WPF to fill available space?