title: Xamarin.Forms ListView size to content
body: <p>I have a pretty large form (adapted mainly for tablets), that has a GridView nesting a two stacklayouts and listview </p>
  
  <p>I have few occurrences where I have a ListView that contains a few single-line items, and I need it to size to content.</p>
  
  <p>So this is my source code for this</p>
  
  <pre><code>&lt;Grid Grid.Row="2" Grid.ColumnSpan="2" HorizontalOptions="FillAndExpand" x:Name="OrderPricingDetails"&gt;
  
                          &lt;Grid.RowDefinitions&gt;
  
                              &lt;RowDefinition Height="90"/&gt;
  
                              &lt;RowDefinition Height="auto" x:Name="OrderPricingDetailsListRow"/&gt;
  
                              &lt;RowDefinition Height="90"/&gt;
  
                          &lt;/Grid.RowDefinitions&gt;
  
                          &lt;StackLayout Grid.Row="0" Orientation="Vertical" Margin="10" Padding="10" x:Name="PackageSelectionSection" &gt;
                              &lt;Label Text="Order Pricing" FontAttributes="Bold" TextColor="Black" /&gt;
                              &lt;Label Text="Listing details for this specific order" FontSize="Small" TextColor="#757575" /&gt;
                              &lt;Frame CornerRadius="5" BackgroundColor="Transparent" HeightRequest="270" BorderColor="#c3c3c3" Padding="10,10,5,10" Margin="0,20,0,0"&gt;
                                  &lt;StackLayout&gt;
  
                                      &lt;FlexLayout JustifyContent="SpaceBetween" HorizontalOptions="FillAndExpand" Direction="Row" AlignItems="Center" x:Name="SelectedPackageSection"&gt;
                                          &lt;StackLayout Orientation="Horizontal"&gt;
                                              &lt;Label Text="Selected Package     " FontSize="Medium" /&gt;
                                          &lt;/StackLayout&gt;
                                          &lt;Label Text="ALA_CARTE_300" x:Name="selectedOfrferDesc" TextColor="#757575" FontAttributes="Bold" FontSize="Small" Grid.Column="1" Grid.ColumnSpan="2"/&gt;
                                          &lt;Label Text="for" FontSize="Medium" /&gt;
                                          &lt;Label Text="LCD" x:Name="selectedOfferPrice" TextColor="#757575" FontAttributes="Bold" FontSize="Small" Margin="0,0,20,0" /&gt;
                                      &lt;/FlexLayout&gt;
  
                                  &lt;/StackLayout&gt;
                              &lt;/Frame&gt;
                          &lt;/StackLayout&gt;
  
                          &lt;StackLayout Grid.Row="1" Orientation="Vertical" Margin="10" Padding="10" x:Name="ConnectionfeeSection" HorizontalOptions="FillAndExpand"&gt;
  
                              &lt;ListView x:Name="OfferList" HasUnevenRows="True" VerticalOptions="Center" Margin="0,10,0,0" SelectionMode="None"&gt;
                                  &lt;ListView.ItemTemplate&gt;
                                      &lt;DataTemplate&gt;
                                          &lt;ViewCell&gt;
  
                                              &lt;Frame CornerRadius="5" OutlineColor="#c3c3c3" Padding="5,10,5,5" Margin="0,10,0,0" BackgroundColor="Transparent"&gt;
                                                  &lt;StackLayout Orientation="Horizontal" Padding="5" BackgroundColor="Transparent" VerticalOptions="Center" &gt;
  
                                                      &lt;FlexLayout JustifyContent="SpaceBetween" HorizontalOptions="FillAndExpand" Direction="Row" AlignItems="Center" x:Name="SelectedConnectionfeeSection"&gt;
                                                          &lt;StackLayout Orientation="Horizontal"&gt;
                                                              &lt;Label Text="{Binding DisplayName}" FontSize="Medium" /&gt;
                                                          &lt;/StackLayout&gt;
                                                          &lt;Label Text="{Binding Amount}" x:Name="selectedConnectionfee" TextColor="#757575" FontAttributes="Bold" FontSize="Small" Margin="0,0,20,0" /&gt;
                                                      &lt;/FlexLayout&gt;
  
                                                  &lt;/StackLayout&gt;
                                              &lt;/Frame&gt;
  
                                          &lt;/ViewCell&gt;
                                      &lt;/DataTemplate&gt;
                                  &lt;/ListView.ItemTemplate&gt;
                              &lt;/ListView&gt;
  
                          &lt;/StackLayout&gt;
  
                          &lt;StackLayout Grid.Row="2" Orientation="Vertical" Margin="10" Padding="10" x:Name="ConnectionTotalSection" &gt;
  
                              &lt;Frame CornerRadius="5" BackgroundColor="Transparent" BorderColor="#c3c3c3" Padding="20,10,5,10" Margin="0,10,0,0"&gt;
  
                                  &lt;StackLayout&gt;
                                      &lt;FlexLayout JustifyContent="SpaceBetween" HorizontalOptions="FillAndExpand" Direction="Row" AlignItems="Center" x:Name="SelectedConnectionTotalSection"&gt;
                                          &lt;StackLayout Orientation="Horizontal"&gt;
                                              &lt;Label Text="Total     " FontSize="Medium" /&gt;
                                          &lt;/StackLayout&gt;
                                          &lt;Label Text="{Binding Total, StringFormat='{0:N}'}" x:Name="selectedConnectionTotal" TextColor="#757575" FontAttributes="Bold" FontSize="Small" Margin="0,0,20,0" /&gt;
                                      &lt;/FlexLayout&gt;
  
                                  &lt;/StackLayout&gt;
                              &lt;/Frame&gt;
  
                          &lt;/StackLayout&gt;
  
                      &lt;/Grid&gt;
  </code></pre>
  
  <p>And this is my code behind.</p>
  
  <pre><code>        OrderPricingDetailsListRow.Height = 280;
  
          OfferList.ItemsSource = connectionsNames;
  
          int i = connectionsNames.Count;
          int heightRowList = 90;
          i = (i * heightRowList);
          OfferList.HeightRequest = i;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/h5Bde.png" rel="noreferrer">My Project image</a></p>
  
  <p>Simply I want to remove that gap between listview and stack layout</p>