title: Change how items are displayed WPF list box
body: <p>I have a WPF window which displays a <code>ListBox</code>. I've changed the <code>ListBox</code>'s item template so that the list box displays rectangular items which can be selected.</p>
  
  <p>Now I'd like to modify the <code>ListBox</code>'s <code>ItemsPanelTemplate</code> so that the items are displayed in a grid instead of either a vertical or horizontal list. Specifically I'd like the first item to go in the top right corner of the <code>ListBox</code> and then second item below it and third under that until the height of the next item would make the column of items taller than the height of the <code>ListBox</code> itself. At that point it should start a second column directly to the right of the first item added. If the total width of all of the columns combined was greater than width of the <code>ListBox</code> then a horizontal scroll bar should appear.</p>
  
  <p>Is there a way to get that effect just by modifying the <code>ItemsPanelTemplate</code> or do I need to extend the <code>ListBox</code> class itself? In either case, how would I got about it?</p>
  
  <p>Thanks for your help!</p>