Displaying a collection of controls in a specific way in WPF

Posted by Alvaro on Stack Overflow See other posts from Stack Overflow or by Alvaro
Published on 2013-10-30T09:50:53Z Indexed on 2013/10/30 9:53 UTC
Read the original article Hit count: 201

Filed under:
|
|
|
|

I have a collection of controls "MyCollection" wich changes in the Runtime. And I have to follow some constraints for that, for example: If my parameter "MyCollection.Count >= 4" the property "NumberOfcolumns" will have the value 2, in order to create new Lines, and show the controls Two per Two.

This is how I'm displaying my collection :

<ItemsControl  ItemsSource="{Binding MyCollection}"  BorderThickness="0"  HorizontalContentAlignment="Center" VerticalContentAlignment="Center" >
  <ItemsControl.ItemsPanel>
    <ItemsPanelTemplate >
      <UniformGrid   Columns="{Binding NumberOfColumns}"  VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent"/>
    </ItemsPanelTemplate>
  </ItemsControl.ItemsPanel>
</ItemsControl>

The problem is that my controls have different sizes, and as In UniformGrids, Cells are uniform... My design is not really pretty, because I have little controls shown in big Cells !!

Can someone help me to solve this problem ?

NB: Please give me a detailled solution if possible, not something like : "Use WrapPanel..."

© Stack Overflow or respective owner

Related posts about wpf

Related posts about xaml