title: How to add a Scrollbar in Listbox in a Grid in XAML?
body: <p>I'm new to XAML and I cant seem to figure this out. I want a two column page that is docked (in winforms term) to its container. The first column has a listbox and I want this to automatically show scrollbar when needed. I was able to do so but only if I set the Height or MaxHeight of the ListBox. My problem with that is the listbox wont grow in size anymore when the main windown/form is resized. What I want is to dock the listbox to the first column so it will resize when the form is resized and show a scrollbar when needed.</p>
  
  <p>Here is the code the does not show a scrollbar:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication3.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="auto" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="*"/&gt;
          &lt;ColumnDefinition Width="*"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;StackPanel Grid.Column="0" Grid.Row="0"&gt;
  
          &lt;ListBox x:Name="lstView"
                   ScrollViewer.VerticalScrollBarVisibility="Auto"
                   ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                    Margin="10"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" Height="20"&gt;
                          &lt;TextBlock Text="{Binding}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here is the code that shows a scrollbar but has a fixed height.</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication3.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="auto" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="*"/&gt;
          &lt;ColumnDefinition Width="*"/&gt;
      &lt;/Grid.ColumnDefinitions&gt;
  
      &lt;StackPanel Grid.Column="0" Grid.Row="0"&gt;
  
          &lt;ListBox x:Name="lstView"
                   ScrollViewer.VerticalScrollBarVisibility="Auto"
                   ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                   Height="200"
                    Margin="10"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" Height="20"&gt;
                          &lt;TextBlock Text="{Binding}"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
          &lt;/ListBox&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>