I would like to make a ListBox
function like a Grid
. Each time a new item is added it should look like a a new GridRow
was added (with a height of star). So if there are two items they will each take up half of the available space. At some point the Grid
row will be smaller than the items MinHeight
at which point the Grid
will expand and a containing ScrollViewer can kick in.
You will see this behavior with a grid inside a ScrollViewer
. However, I need to get this working with a ListBox
so I can just set the ItemsSource
, create a DataTemplate
and move on.
The problem with the default ListBox
ItemsPanel
is that it will not let my first item expand to fill all the available space.
UPDATE: Here's the code to get it working:
<ListBox VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" Width="Auto" Height="Auto">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="1"></UniformGrid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
This SO post has some pretty good information that seems relevant to your post WPF - Why Listbox items do not fill uniformgrid
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With