title: Bind the height of a grid row to it's contents in WPF
body: <p>I have a grid with a few rows.  In the top row, I have an ItemsControl that is bound dynamically to a collection and uses a DataTemplateSelector and ItemsPanelTemplate (with a single horizontally arranged WrapPanel).  Here's a stripped-down version of what I have so far:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="40" /&gt;
          &lt;RowDefinition Height="2" /&gt;
          &lt;RowDefinition Height="*" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;GridSplitter Background="#666" Grid.Row="1" Height="Auto" Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /&gt;
      &lt;ItemsControl x:Name="items" Background="#DDD" Grid.Row="0" ItemTemplateSelector="{StaticResource itemTemplateSelector}"&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;WrapPanel Orientation="Horizontal" /&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
      &lt;/ItemsControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Instead of setting that first row's height to 40, I'd like to set it dynamically based on the minimum height that the ItemsControl must be to fit all of its contents.  Since the ItemsControl's height is being constrained by the Grid Row's height, I can't figure out which element I should be binding and to what element's property I should be binding it to.</p>
  
  <p>It would make sense to bind the Grid Row's Height to the "desired height" of the ItemsControl.  So, I found the DesiredSize property and bound my RowDefinition's Height to the ItemsControl's DesiredSize.Height.  That works when it first loads, but does not update as I resize the control (remember, I'm using a WrapPanel as my ItemsPanelTemplate, so as I resize the window, the height of the ItemsControl should be changing).</p>
  
  <p>Does anyone know if this kind of situation is even supported by the binding framework, or would I need to add event handler code to accomplish this?</p>
  
  <p>Thanks.</p>