title: WPF Restrict size of an expander
body: <p>I have a multiple treeviews inside expanders, which can grow in height along with the content. But when the height gets larger than the window's size, it goes outside the window. </p>
  
  <p>The obvious solution would be to set the MaxHeight of the Treeview, but I can't determine it easily, because the available height depends on</p>
  
  <ul>
  <li>Window height</li>
  <li>The other expanders (open/closed)</li>
  </ul>
  
  <p>What do I need to change to make the treeview's height still grow automaticly, but never larger than the window's height?</p>
  
  <pre><code>&lt;StackPanel CanVerticallyScroll="True" ClipToBounds="False" Height="Auto" Name="StackPanel2" Width="250" DockPanel.Dock="Left" Orientation="Vertical" VerticalAlignment="Top" CanHorizontallyScroll="False" Margin="5"&gt;
      &lt;Border BorderThickness="0" CornerRadius="5" Padding="1" BorderBrush="Red" Margin="0,5" &gt;
          &lt;Expander Header="Expander3" Height="Auto" IsExpanded="False" Width="Auto" Margin="2" BorderThickness="1"&gt;
             &lt;Grid  Height="Auto" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" &gt;
  
              &lt;TreeView Height="Auto" BorderThickness="1" Margin="0,0,0,0" Padding="7" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" &gt;
             &lt;/TreeView&gt;
  
          &lt;/Grid&gt;
      &lt;/Expander&gt;
      &lt;/Border&gt;
  &lt;/StackPanel&gt;
  </code></pre>