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?
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
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.
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.
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.
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.
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 Height="Auto"/>
<RowDefinition Height="Auto" MaxHeight="*"/>
<RowDefinition Height="Auto"/>