My application displays multiple items in an ItemsControl
that uses a UniformGrid
as its ItemsPanel
.
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!-- Arrange all items vertically, distribute the space evenly -->
<UniformGrid Columns="1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Now each of the items will take as much space as there is and the full width. That's how it should be. But each item must not get smaller than a certain height, say 250 pixels. Therefore, my ItemsControl
is put inside a ScrollViewer
which will start to scroll if the minimum height doesn't fit on the screen anymore (but fill until then).
Setting each item's MinHeight
property to 250 will make it taller but won't change how the UniformGrid
arranges them in any way, so they're clipped. That's not the solution.
Setting the entire ItemsControl's or the UniformGrid's MinHeight
property does work, but then I need to calculate it from the number of items. A good place to get the updated number of items is to override the OnItemsChanged
method in my ItemsControl
code-behind. But that won't give me the actual items panel. I have the following code for that in another project, but it always returns null here:
ItemsControl itemsControl = ItemsControl.GetItemsOwner(this);
So that doesn't work, too.
Walking the visual tree is probably not an option, too, because it's too late. I need to set the minimum height before that items panel is arranged so that it won't flicker. (I generate complex content on a size change so any late layouting must be avoided.)
What options do I have to get what I need?
I may drop the UniformGrid
in favour of something else, if it's possible. Any suggestions?