tags:

views:

165

answers:

1

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 Grid Row 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: Heres 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>
+1  A: 

This SO post has some pretty good information that seems relevant to your post http://stackoverflow.com/questions/399713/wpf-why-listbox-items-do-not-fill-uniformgrid

Jacob Adams
Thanks that helped, I don't use the uniform grid much so I never thought of it.
Kelly