The stackpanel is not co-operating. We have a fixed width, and a variable number of items to lay out left-to-right inside it.
We have a an items control that lays them out with a stack panel:
<ItemsControl x:Name="testItems"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Stacktest:ItemControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
But this doesn't size the items correctly. They are always the same size, regardless of how much space is available. If there are too many items they are cut off on the right, rather than sized so that they all fit in. Any idea how to accomplish this? I'd use a grid if the number of items was constant, but it isn't. It's typically 1-4 items.
It would be nice if the ItemsPanelTemplate could be a grid with a variable number of columns. But I don't know if that (or something with the same result) is possible in an ItemsPanelTemplate.
Is the answer to write a special subclass of panel that allocates equal width to contained items?