title: WPF: Resize item size to have all items visible
body: <p>I've the following code:</p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding SubItems}"&gt;
      &lt;ItemsControl.ItemsPanel&gt;
          &lt;ItemsPanelTemplate&gt;
              &lt;WrapPanel Orientation="Horizontal"&gt;&lt;/WrapPanel&gt;
          &lt;/ItemsPanelTemplate&gt;
      &lt;/ItemsControl.ItemsPanel&gt;
      &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;Grid   Margin="10"&gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition Height="*"&gt;&lt;/RowDefinition&gt;
                      &lt;RowDefinition Height="Auto"&gt;&lt;/RowDefinition&gt;
                  &lt;/Grid.RowDefinitions&gt;
                  &lt;Image Source="{Binding Image}" &gt;&lt;/Image&gt;
                  &lt;TextBlock Text="{Binding Name}" Grid.Row="1"  HorizontalAlignment="Center"/&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
      &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>Currently if I run this code, every item(grid) tries to take the full space available and I've only 1-2 items visible over the 20+ I've in my <code>SubItems</code> collections.</p>
  
  <p>If I set a <code>MaxWidth</code> to my Grid, I see all of them, but when I maximize the window, I've a lot of free space.</p>
  
  <p>If I don't set any width, I've this:
  <a href="https://i.stack.imgur.com/rM5ap.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rM5ap.png" alt="enter image description here"></a></p>
  
  <p>If I set a width and increase the size, I've this:
  <a href="https://i.stack.imgur.com/9vr5e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9vr5e.png" alt="enter image description here"></a></p>
  
  <p>The goal is to have something like the second case, but without having to set a width, and having it scale if I increase the window size.</p>
  
  <p><strong>Edit2</strong>
  I tried with UniformGrid, but two issues. With two elements, it seems it absolutely wants to have 4 column and 3 rows. Even if would be better with 3 column 4 rows:
  <a href="https://i.stack.imgur.com/J4hs1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J4hs1.png" alt="enter image description here"></a></p>
  
  <p>Also, when the window is reduced, the images are cut:
  <a href="https://i.stack.imgur.com/wx8UC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wx8UC.png" alt="enter image description here"></a></p>