問題:
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?