title: Adjusting WPF control size in order to fit to window size
body: <p>How can I check how many lines of the ListView fit in the window (Main Window).
  I assume that the window is maximized, and only the system settings determine the size of the window. 
  ListView is docked in DockPanel with the option FillLastChild. </p>
  
  <p>Does WPF provide mechanisms to automate such a operation?</p>
  
  <p>Regards.</p>
  
  <p>Here is my WPF. I'd like to know how many items fit in "lstBox" in order to control paging using Back and Next buttons.  </p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
          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"
          xmlns:local="clr-namespace:WpfApplication1"
          mc:Ignorable="d"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Window.Resources&gt;
          &lt;DataTemplate x:Key="ListBoxTemplate"&gt;
              &lt;Grid &gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition /&gt;
                      &lt;ColumnDefinition /&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;TextBlock Grid.Column="0" Text="{Binding Path=Name}" TextWrapping="Wrap"  /&gt;
                  &lt;TextBlock Grid.Column="1" Text="{Binding Path=Value}" TextWrapping="Wrap"  /&gt;
              &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
  
      &lt;DockPanel x:Name="MainPanel" LastChildFill="True"&gt;
      &lt;Grid DockPanel.Dock="Bottom"&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="40" /&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="15*"/&gt;
              &lt;ColumnDefinition Width="75*"/&gt;
              &lt;ColumnDefinition Width="15*"/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Button x:Name="btnNext" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Height="23" Content="Next" HorizontalAlignment="Right" Margin="0,6,0,0" Width="40" /&gt;
          &lt;Button x:Name="btnBack" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="40" Height="23" Content="Back" Margin="0,6,0,0" /&gt;
      &lt;/Grid&gt;
      &lt;ItemsControl x:Name="lstBox" ItemsSource="{Binding}"  ItemTemplate="{DynamicResource ListBoxTemplate}" BorderBrush="#FF000000" 
                    BorderThickness="1,1,1,1"  VerticalAlignment="Stretch" /&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>