0

I have an one dimensional ObservableCollection. How can I display it as a multi-dimensional collection (Matrix)?

E.g: I have list of images (urls) I want to display it so there would be three images in a row and as many rows as count/3 will be equal to.

I found how I can bound two dimensional list to a grid, but nothing like I want.

Is this is possible?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Alex Kapustian
  • 4,843
  • 14
  • 49
  • 77

1 Answers1

0

Yeah you can by overriding the ItemsPanel for your ItemsControl like this -

<ItemsControl>
   <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
         <UniformGrid Rows="3" Columns="3"/>
      </ItemsPanelTemplate>
   </ItemsControl.ItemsPanel>
</ItemsControl>
Rohit Vats
  • 77,212
  • 12
  • 152
  • 179
  • Ok, but how it will know how many items in a row and how many rows just by binding? or I need manually initialize all the items...? – Alex Kapustian Oct 14 '12 at 18:24
  • Instead use `UniformGrid` and specify the number of rows and columns as per your need. See the updated answer. – Rohit Vats Oct 14 '12 at 18:27
  • So, don't set the `Row` field. It will be set dynamically based on the number of items in your collection. – Rohit Vats Oct 14 '12 at 18:31
  • Say if you have `24` items then it will automatically create `8` rows of `3` columns each. – Rohit Vats Oct 14 '12 at 18:31
  • Either you can omit setting both `Rows` and `Columns`. UniformGrid arrange the items itself as per the available height and width. – Rohit Vats Oct 14 '12 at 18:47
  • instead of uniform grid you can use normal grid and set the number of columns and rows dynamically as Rachel said here : http://stackoverflow.com/questions/9000549/how-can-i-dynamically-add-a-rowdefinition-to-a-grid-in-an-itemspaneltemplate – Bizhan Oct 14 '12 at 21:11
  • `Rows` and `Columns` can be set dynamically here through `Binding`. Rows and Columns are normal DP's which supports binding too.. :) – Rohit Vats Oct 15 '12 at 06:00