title: WPF ItemsControl elements - Resize content based on the window size (Anchoring)
body: <p>im working with wpf and i have the problem that i want to bind a collection to an element which resize its content based on the window size.</p>
  
  <p>To make it more clear a little example:
  With static behaviour i would do something like that.</p>
  
  <pre><code>&lt;Grid Margin="10,10,10,10"&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="50*"/&gt;
          &lt;RowDefinition Height="50*"/&gt;
          &lt;RowDefinition Height="50*"/&gt;
          &lt;RowDefinition Height="50*"/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Button Grid.Row="0"&gt;&lt;/Button&gt;
      &lt;Button Grid.Row="1"&gt;&lt;/Button&gt;
      &lt;Button Grid.Row="2"&gt;&lt;/Button&gt;
      &lt;Button Grid.Row="3"&gt;&lt;/Button&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>In that case all the Buttons would grow/shrink with the window.</p>
  
  <p>But now i want to have it more dynamic.
  I have an ObservableCollection which contains all the elements to be added (dynamic amount).
  For the first implementation ive added all the elements to a StackPanel. But the controls within the StackPanel dosent resize so that i think about using a grid instead.</p>
  
  <p>Actual solution:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;DataTemplate DataType="{x:Type local:OwnObject}"&gt;
          &lt;Button DataContext="{Binding}" Content="{Binding Text}" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;ItemsControl ItemsSource="{Binding SubItems}"&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;StackPanel x:Name="stackPanel" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
      &lt;/ItemsControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>How is it possible to use the ItemsControl to generate one row for each element and add it to that row? Other solutions to deal tith the problem are also welcome.</p>