title: How to make a ListView inside a grid in WPF fill the whole screen, even when resized
body: <p>I have a control which is a grid where the first row contains some buttons, with fixed height, and the second (and last) row contains a ListView. Then I have a main screen which contains only a menu and this user control above. I would like to have the size of the ListView as the maximum for the window, which means that if the window is maximized the ListView will be large, in case the window is smaller, so is the ListView (with vertical scroll to help navigating through items).</p>
  
  <p>This is how I am doing it:
  Window:</p>
  
  <pre><code>&lt;Window x:Class="TestUI.MainView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      Width="auto" Height="auto"
      MinHeight="300" MinWidth="300"
      Title="Test"
      DataContext="{Binding MainViewModel, Source={StaticResource Locator}}" &gt;
  
  &lt;StackPanel Orientation="Vertical" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"&gt;
      &lt;DockPanel&gt;
          &lt;Menu DockPanel.Dock="Top" &gt;
              &lt;MenuItem Header="Item 1" Command="{Binding Command1}"/&gt;
              &lt;MenuItem Header="Item 2" Command="{Binding Command2}"/&gt;
              &lt;MenuItem Header="Item 3" Command="{Binding Command3}"/&gt;
          &lt;/Menu&gt;
      &lt;/DockPanel&gt;
      &lt;DockPanel LastChildFill="True"&gt;
          &lt;ScrollViewer Content="{Binding Content}" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled" DockPanel.Dock="Bottom" /&gt;
      &lt;/DockPanel&gt;
  &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>User Control:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="35" /&gt;
          &lt;RowDefinition Height="*" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;StackPanel Grid.Row="0" Margin="5, 5, 5, 5" Orientation="Horizontal"&gt;
          &lt;Button Content="New" Width="60" Command="{Binding NewCommand}"/&gt;
          &lt;Button Content="Remove" Width="60" Margin="10, 0, 0, 0" Command="{Binding RemoveCommand}" /&gt;
      &lt;/StackPanel&gt;
      &lt;DockPanel Grid.Row="1" Margin="5,5,5,5" LastChildFill="True" HorizontalAlignment="Stretch"&gt;
          &lt;ListView x:Name="ListView" SelectionMode="Single" DockPanel.Dock="Top" ItemsSource="{Binding Entities}" SelectedItem="{Binding SelectedEntity}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch"&gt;
              &lt;ListView.View&gt;
                  &lt;GridView&gt;
                      &lt;GridViewColumn Width="auto" Header="Product" DisplayMemberBinding="{Binding Description}"/&gt;
                  &lt;/GridView&gt;
              &lt;/ListView.View&gt;
          &lt;/ListView&gt;
      &lt;/DockPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Could you please help me?</p>
  
  <p>Thank you!</p>