title: WPF XAML ListView with ScrollBars
body: <p>I have a ListView which is showing both scroll bars.  To achieve that, I places my ListView within a Border located in a Grid like below:</p>
  
  <pre><code>&lt;Window ...
      MinWidth="600" MinHeight="500" Width="800" Height="500"
      Topmost="True"
      WindowStartupLocation="CenterScreen" 
      SizeToContent="Height" WindowStyle="None"&gt;
  
      &lt;Window.Resources&gt;
          &lt;ResourceDictionary&gt;
              ...
          &lt;/ResourceDictionary&gt;
      &lt;/Window.Resources&gt;
  
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="Auto"/&gt;
              &lt;RowDefinition Height="*" MinHeight="60"/&gt;
              &lt;RowDefinition Height="48"/&gt;
          &lt;/Grid.RowDefinitions&gt;
  
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="*"/&gt;
              &lt;ColumnDefinition Width="10"/&gt;
              &lt;ColumnDefinition Width="*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
          &lt;Grid Grid.Row="1"&gt;
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="32"/&gt;
                  &lt;RowDefinition Height="370"/&gt;  &lt;-- THIS IS HARDCODED TO 370 BUT I NEED IT TO BE RESIZABLE
              &lt;/Grid.RowDefinitions&gt;
  
              &lt;Grid Margin="5,0,0,0"&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="4"/&gt;
                      &lt;ColumnDefinition Width="346*"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;TextBlock Text="{Binding MyName}" Grid.Column="1"
                         Style="{StaticResource MyNameStyle}" Margin="0,5,0,5" /&gt;
  
              &lt;/Grid&gt;
  
              &lt;Border BorderBrush="{StaticResource MyBrush}" Grid.Row="1" Grid.Column="0" &gt;
                  &lt;ListView
                      x:Name="lstMyListView" 
                      Margin="0,0,0,0"
                      BorderBrush="Transparent"
                      ItemsSource="{Binding MyItems}" 
                      SelectedIndex="0"
                      ScrollViewer.CanContentScroll="True"
                      ScrollViewer.VerticalScrollBarVisibility="Auto"&gt;
                    ...
                    ...
                  &lt;/ListView&gt;
                ...
                ...
              &lt;/Border&gt;
              ...
              ...
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>This is all in a form that is resizable.  Therefore, the ListView should also resize but it should do that only when user resizes the form.  The problem with my hard coded value above is obvious, the ListView will not resize but stay at constant height=370.</p>
  
  <p>I know I can set this to 370* but in that case, my List will resize to fit all items.  I want to limit this so that resizing only occurs when user resizes the form.  So, ListView should show scroll bars if there are more items and as the user resizes form, that scroll bar should go away if form is resized to height that can accommodate all items in ListView.</p>
  
  <p><strong>UPDATE:</strong>
  Instead of hard coding the height to 370 above, I have tried setting the height to <em>, Auto, and 370</em>.  All of these would expand the ListView (and therefore form, too) to accommodate all items in the ListView.</p>
  
  <p><strong>UPDATE 2:</strong>
  Updated XAML to show whole tree structure.</p>
  
  <p><strong>UPDATE 3:</strong>
  As per Rachel's suggestion, set hardcoded 370 to "*" in commented line above in XAML and that produces form resized so that the ListView fits all items in it.  I added screenshot showing the form as it opens and a screenshot showing how it should look like when it opens.  As you can see, it resizes hightwise to accomodate all itesm.</p>
  
  <p>What I need is that form and ListView stay in their set size and resize only if user resizes the form.</p>
  
  <p><a href="https://i.stack.imgur.com/hdAvq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hdAvq.png" alt="enter image description here"></a></p>