title: Scale images in listview to fit
body: <p>I'm trying to make a listview where each item is an image. I want the listview to display the items horizontally. If the view box items won't fit horizontally in the window I want a horizontal scroll bar. If the list items won't fit vertically within the window I want the images to scale down so they fit. Instead of the images scaling to fit I seem to be getting a vertical scrollbar on the listview. </p>
  
  <p>At the moment when the window is resized vertically it causes a vertical scrollbar to appear on the listview. I've tried various options around setting the image height to the height of the ancestor listview but I can't make it work correctly. How do I achieve my desired behaviour?</p>
  
  <pre><code>&lt;Window x:Class="ViewBoxExample.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:ViewBoxExample"
          mc:Ignorable="d"
          d:DataContext="{d:DesignInstance Type=local:MainWindow}"
          Title="Viewbox Test"
          Height="400" Width="600"&gt;
      &lt;Window.Resources&gt;
          &lt;DataTemplate x:Key="ItemTemplate" &gt;
                  &lt;Border BorderBrush="Black" BorderThickness="2" &gt;
                      &lt;Image Margin="2" Source="image.png" /&gt;
                  &lt;/Border&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="*"/&gt;
              &lt;RowDefinition Height="Auto"/&gt;
         &lt;/Grid.RowDefinitions&gt;
          &lt;ListView VerticalAlignment="Stretch"
                    ItemTemplate="{StaticResource ItemTemplate}"
                    ItemsSource="{Binding Items}"&gt;
              &lt;ListView.ItemsPanel&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;/StackPanel&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/ListView.ItemsPanel&gt;
          &lt;/ListView&gt;
          &lt;Grid Grid.Row="1" Height="100"&gt;
              &lt;!--placeholder for more content--&gt;
          &lt;/Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>