title: Bind ListViewItem's height to the ListView from dataTemplate
body: <p>I have a ListView in my <strong>Windows Store App</strong>, which selects a template through dataTemplateSelector. In the ItemTemplate of ListView, i have an image. I don't want to fix the height and width of the image, i want to allow it to adjust itself with the space available. So the image can be displayed bigger in big screen size.</p>
  
  <p>Following is my ListView XAML:</p>
  
  <pre><code>  &lt;ListView Name="MyListView"  ItemTemplateSelector="{StaticResource MyTemplateConverter}"
                                Height="{Binding ActualHeight, ElementName=scroll, Converter={StaticResource BottomMarginConverter}}" Width="{Binding ActualWidth, Converter={StaticResource GVWIdthConverter}, ElementName=scroll}"
                                Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Tapped="MyGridView_Tapped"&gt;
                          &lt;ListView.ItemsPanel&gt;
                              &lt;ItemsPanelTemplate&gt;
                                  &lt;VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Stretch" /&gt;
                              &lt;/ItemsPanelTemplate&gt;
                          &lt;/ListView.ItemsPanel&gt;
                          &lt;ListView.ItemContainerStyle&gt;
                              &lt;Style TargetType="ListViewItem"&gt;
                                  &lt;Setter Property="VerticalContentAlignment" Value="Stretch" /&gt;
                                  &lt;Setter Property="Margin" Value="0,5,0,5" /&gt;
                                  &lt;Setter Property="Background" Value="LightCyan" /&gt;
                                  &lt;Setter Property="BorderBrush" Value="Black" /&gt;
                                  &lt;Setter Property="BorderThickness" Value="3" /&gt;
                              &lt;/Style&gt;
                          &lt;/ListView.ItemContainerStyle&gt;
                      &lt;/ListView&gt;
  </code></pre>
  
  <p>I have set <em>VerticalContentAlignment</em> to <em>Stretch</em>, this stretches my <em>ListViewItem</em> to the size of <em>ListView</em>, but the problem is when the image inside the Item is bigger, it increases the size of <em>ListViewItem</em> larger than <em>ListView</em>. I have also tried setting the height of <em>ListViewItem</em> in the above code by adding</p>
  
  <pre><code>&lt;Setter Property="Height" Value="{Binding ActualHeight, ElementName=MyGridView}" /&gt;
  </code></pre>
  
  <p>Following is the code of my ItemTemplate, which is being selected through ItemTemplateSelector,</p>
  
  <pre><code>&lt;DataTemplate x:Key="PhotoTemplate"&gt;
          &lt;Grid x:Name="PhotoTemplateGrid" Width="400" Margin="2"  Background="LightPink" &gt;
  
              &lt;Grid.RowDefinitions&gt;
                  &lt;RowDefinition Height="90"/&gt;
                  &lt;RowDefinition Height="*"/&gt;
                  &lt;RowDefinition Height="50"/&gt;
  
              &lt;/Grid.RowDefinitions&gt;
  
              &lt;Grid  Grid.Row="0" Margin="5" HorizontalAlignment="Stretch"  &gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="90" /&gt;
                          &lt;ColumnDefinition Width="*" /&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
  
                      &lt;Image Grid.Column="0" Source="{Binding from.photoUrl}" Height="70" HorizontalAlignment="Center"  VerticalAlignment="Center"  Width="70" /&gt;
  
                      &lt;StackPanel Orientation="Vertical" Margin="10,10,0,0"  Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"&gt;
                          &lt;TextBlock Grid.Column="1" Text="{Binding from.Name}" Style="{StaticResource SubHeaderText}"  VerticalAlignment="Top"  
                              IsHitTestVisible="false" TextWrapping="NoWrap" Foreground="{StaticResource StalkerBlueThemeBrush}" /&gt;
                          &lt;TextBlock Text="{Binding created_Time, Converter={StaticResource TextDateConverter}}" Margin="0,0,0,0" Style="{StaticResource BaselineTextStyle}"  VerticalAlignment="Top"  
                              IsHitTestVisible="false" TextWrapping="NoWrap"  FontSize="12" /&gt;
                      &lt;/StackPanel&gt;
  
                  &lt;/Grid&gt;
  
              &lt;Grid Grid.Row="1" &gt;
                  &lt;Grid.RowDefinitions&gt;
                      &lt;RowDefinition Height="Auto" /&gt;
                      &lt;RowDefinition Height="Auto"/&gt;
                      &lt;RowDefinition Height="*"   /&gt;
                  &lt;/Grid.RowDefinitions&gt;
  
                  &lt;TextBlock Grid.Row="0" Margin="5,0,5,0" TextAlignment="Center" MaxHeight="40" HorizontalAlignment="Stretch" Text="{Binding message}"  Style="{StaticResource BaselineTextStyle}"
                          TextTrimming="WordEllipsis" IsHitTestVisible="false" TextWrapping="Wrap" VerticalAlignment="Center"  /&gt;
  
                  &lt;TextBlock Grid.Row="1" MaxHeight="20" Margin="5,0,5,0" TextAlignment="Center" Text="{Binding description}" Style="{StaticResource BaselineTextStyle}"
                      TextTrimming="WordEllipsis" IsHitTestVisible="false" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Stretch"   /&gt;
  
                  &lt;Image Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform" Source="{Binding picture}" Margin="2"     /&gt;
  
              &lt;/Grid&gt;
  
              &lt;Grid Grid.Row="2" Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" &gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="15" /&gt;
                          &lt;RowDefinition Height="*"/&gt;
                      &lt;/Grid.RowDefinitions&gt;
                      &lt;Grid Grid.Row="0" Height="Auto" Background="White" &gt;
                          &lt;Polygon Points="15,0 0,15 30,15" Stroke="LightGray" Fill="LightGray" Margin="20,0,0,0" /&gt;
                      &lt;/Grid&gt;
                      &lt;Grid Grid.Row="1" HorizontalAlignment="Stretch"&gt;
  
                          &lt;TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,0,0" Text="View all comments" Style="{StaticResource BaselineTextStyle}" Foreground="{StaticResource BlueThemeBrush}" /&gt;
  
                          &lt;StackPanel  Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,5,0"&gt;
  
                              &lt;Image Height="15" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,0,0,0"  Width="25" Source="ms-appx:///Assets/CtBlueSmall.png" /&gt;
                              &lt;TextBlock  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Text="{Binding CtCount}" Foreground="White"   /&gt;
                              &lt;Image  Height="15" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="25" Source="ms-appx:///Assets/LeBlueSmall.png" /&gt;
                              &lt;TextBlock  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Text="{Binding LeCount}" Foreground="White"   /&gt;
  
                          &lt;/StackPanel&gt;
                      &lt;/Grid&gt;
                  &lt;/Grid&gt;
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>The Grid at Row Number 1 <code>&lt;Grid Grid.Row="1" &gt;</code>, contains the image which makes the height go larger than the ListView. I want to allow this Grid to stretch itself to the size of its parent. But not cross the size of its parent. in other word, i simply want to bind its height to its parent. Please help me out, i am stuck here.</p>