How can I use automatic row height in a WPF Grid control but limit it to the extent that the Grid doesn't scroll altogether?
如何在WPF网格控件中使用自动行高,但将其限制为Grid不完全滚动的程度?
Here's my UI:
这是我的用户界面:
- 1st row: Auto height, contains a label and text input (in reality there's more of these rows)
- 2nd row: Contains a ListView of flexible height, depending on the number of items
- 3rd row: Auto height, contains buttons to control the list items above
第1行:自动高度,包含标签和文本输入(实际上有更多这些行)
第2行:包含灵活高度的ListView,具体取决于项目数
第3行:自动高度,包含用于控制上面列表项的按钮
The ListView should be auto-sized, so it only takes so much space as its item rows. When a row is added, the ListView increases in height.
ListView应该是自动调整大小的,因此它只需要占用项目行的空间。添加行时,ListView的高度会增加。
The buttons below the ListView should remain directly under the ListView, with no variable gap in between. The space between ListView and Buttons should always be exactly 6 pixels, to name a value.
ListView下面的按钮应该直接保留在ListView下面,两者之间没有可变的间隙。 ListView和Buttons之间的空格应始终精确为6个像素,以命名值。
As more items are added to the ListView, the buttons move down with the ListView's height. When the window isn't large enough to display them all, the buttons must remain visible at the very bottom of the available space and the ListView should begin scrolling its content.
随着更多项目添加到ListView,按钮向下移动ListView的高度。当窗口不够大而无法全部显示时,按钮必须在可用空间的最底部保持可见,并且ListView应开始滚动其内容。
So with a short list, it's like this: All rows of the Grid are auto-height and there's much empty space at the bottom. With a long list, it's like the middle row is 1*-height, the Grid spans the entire window, the buttons are visible at the bottom and the list spans the remaining space, automatically scrolling its content.
所以有了一个简短的列表,就像这样:网格的所有行都是自动高度,底部有很多空白空间。使用长列表,就像中间行是1 * - 高,网格跨越整个窗口,按钮在底部可见,列表跨越剩余空间,自动滚动其内容。
How can I do that?
我怎样才能做到这一点?
I found the RowDefinition.MaxHeight property, but it doesn't accept a * height. Otherwise I'd have tried with something like this:
我找到了RowDefinition.MaxHeight属性,但它不接受* height。否则我会尝试这样的事情:
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" MaxHeight="*"/>
<RowDefinition Height="Auto"/>
1 个解决方案
#1
0
You can set a fixed height and minheight for all your RowDefinitions besides the second and place a scrollviewer around your ListView.
除了秒之外,您可以为所有RowDefinition设置固定高度和minheight,并在ListView周围放置一个scrollviewer。
EDIT: Ok, no scrollviewer, the ListView can scroll its content by itself.
编辑:好的,没有滚动查看器,ListView可以自己滚动其内容。
#1
0
You can set a fixed height and minheight for all your RowDefinitions besides the second and place a scrollviewer around your ListView.
除了秒之外,您可以为所有RowDefinition设置固定高度和minheight,并在ListView周围放置一个scrollviewer。
EDIT: Ok, no scrollviewer, the ListView can scroll its content by itself.
编辑:好的,没有滚动查看器,ListView可以自己滚动其内容。