title: autosizing listbox in Silverlight
body: <p>I'm doing something that seems like it should be pretty easy, but I'm not getting the results that I want.  Maybe someone can give me a hint...</p>
  
  <p>Suppose I have a Silverlight user control.  I have a Grid, and 2 row definitions.
  The top row is going to display search results in a ListBox.  I have an item template assigned to the listbox.</p>
  
  <p>The bottom row contains some controls. </p>
  
  <p>What I want:</p>
  
  <ul>
  <li>The bottom row should be a fixed height, and I do not want for it to scroll off of the screen.</li>
  <li>The top row (and the list box) should "squish" vertically so that it always uses all of the space available minus the space used by the bottom row.</li>
  <li>So, if the user resizes their browser window, the listbox will grow and shrink vertically.</li>
  <li>If the listbox cannot display all of its results on one screen, I want it to display a scrollbar.</li>
  </ul>
  
  <p>Here's what I have so far:</p>
  
  <ul>
  <li>The listbox and row will grow and shrink dynamically.  </li>
  <li>However, If their are too many results for the listbox to display, it just grows vertically.  It will push my bottom grid row right off of the screen.</li>
  </ul>
  
  <p>Here are my row definitions:</p>
  
  <pre>
  <code>
          &lt;Grid.RowDefinitions>
              &lt;RowDefinition MinHeight="350" Height="*"/>
              &lt;RowDefinition Height="175"/>
          &lt;/Grid.RowDefinitions>
  </code>
  </pre>
  
  <p>Here's my listbox</p>
  
  <pre>
  <code>
  &lt;ListBox 
      ScrollViewer.VerticalScrollBarVisibility="Auto" 
      SelectionMode="Single" 
      SelectedItem="{Binding SelectedItem, Mode=TwoWay}" 
      ItemsSource="{Binding View}" 
      ItemTemplate="{StaticResource SearchResultItemTemplate}" 
      Grid.Row="0" />
  </code>
  </pre>