0

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..." Please also notice that I'm following the MVVM, so no code behind.

NTinkicht
  • 972
  • 2
  • 12
  • 34
  • Could you please explain some more details how you want your Ui to look? – Kumareshan Oct 30 '13 at 10:02
  • The 'use a `WrapPanel`' suggestion that you don't want to hear is the simple solution... your only other solution is for you to [implement your own custom `Panel`](http://www.codeproject.com/Articles/37348/Creating-Custom-Panels-In-WPF). – Sheridan Oct 30 '13 at 10:02
  • @Sheridan, I'm not against using WrapPanel ! I'm just demanding to give me more details ! because to define the number of columns in a WrapPAnel, you have to manipulate the "Size", but in my case, I have just the number of element to refer to ... – NTinkicht Oct 30 '13 at 10:09
  • 1
    @Alvaro, while there is no problem with your comment, I'd just like to point out that your word 'demanding' might not be a good word to use here... maybe 'requesting' or 'asking' might be received better by English speaking users. Regarding your question, you do not need to set the number of columns in a `WrapPanel`, that will depend on the overall size of your containing control and the size of the elements inside. – Sheridan Oct 30 '13 at 10:14
  • 1
    @Sheridan, I'm sorry for this word, it was what Google translator gave to me, really sorry... My problem with the WrapPanel is that I cant see how to force it to create new line when I'll have more than 2 controls in my collection. because I think that working with the size can't ensure that ! as it can put one small control + one big control in one line. It can also put 3 small controls in the same line !! Hope I was clear, and sorry again for that word. – NTinkicht Oct 30 '13 at 10:22
  • @Alvaro, like I said, there's no problem... I didn't think you fully understood that word, which is why I let you know. I understand that English is not the main language used for many users here. Regarding the `WrapPanel`, just set a `Width` on it and add items and it will do the rest. You *may* need to set the `ScrollViewer.HorizontalScrollBarVisibility` property to `Disabled` also. – Sheridan Oct 30 '13 at 10:35
  • @Sheridan, I can't specify any width, because I don't have this information. Anyway, thanks for your comments and supports :) . – NTinkicht Oct 30 '13 at 10:49
  • You can set it using a `Grid` with a column `Width` of `Auto` or `*` I believe, so you wouldn't need to know any exact `Width` values. – Sheridan Oct 30 '13 at 10:55

0 Answers0