title: Xamarin Forms - iOS dynamic ViewCell size in a ListView
body: <p>The following XF app (code below) creates a simple ListView with 2 custom cells.  Tapping on a cell uses the IsVisible property to show the second label.</p>
  
  <p>On Android this works great as the size of the ViewCell resizes to fit the currently displayed contents.  When the Detail item is made visible, the ViewCell expands to show the detail.</p>
  
  <p>On iOS, this isn't working.</p>
  
  <p>Here is how the app appears on first launch...</p>
  
  <p><a href="https://i.stack.imgur.com/w25YX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w25YX.png" alt="enter image description here"></a></p>
  
  <p>When you tap the first ViewCell, the IsVisible property is tripped and the Detail item shows.  However, the ViewCell remains the same height causing it to overflow as seen below...</p>
  
  <p><a href="https://i.stack.imgur.com/jucmz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jucmz.png" alt="enter image description here"></a></p>
  
  <p>How can this be accomplished on the iOS side?</p>
  
  <p>Here is the code...</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>  &lt;ContentPage.Content&gt;
      &lt;ListView x:Name="___list" Margin="50" HasUnevenRows="True"&gt;
        &lt;ListView.ItemTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;ViewCell&gt;
              &lt;StackLayout&gt;
                &lt;StackLayout.GestureRecognizers&gt;
                  &lt;TapGestureRecognizer Command="{Binding CellTap}" /&gt;
                &lt;/StackLayout.GestureRecognizers&gt;
                &lt;Label Text="{Binding Title}" /&gt;
                &lt;Label Text="{Binding Detail}" FontSize="30" IsVisible="{Binding ShowDetails}" /&gt;
              &lt;/StackLayout&gt;
            &lt;/ViewCell&gt;
          &lt;/DataTemplate&gt;
        &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
    &lt;/ContentPage.Content&gt;
  </code></pre>
  
  <p><strong>C#</strong></p>
  
  <pre><code>public partial class MainPage : ContentPage
  {
      public MainPage()
      {
          InitializeComponent();
  
          ___list.ItemsSource = new List&lt;Element&gt;() {
                  new Element() {
                      Title="First Element",
                      Detail = "First Element Details"
                  },
                  new Element() {
                      Title="Second Element",
                      Detail = "Second Element Details"
                  }
              };
      }
  }
  public class Element : INotifyPropertyChanged
  {
      public Element()
      {
          CellTap = new Command(() =&gt;
          {
              ShowDetails = !ShowDetails;
          });
      }
  
      public ICommand CellTap { get; private set; }
  
      private string _title;
      public string Title
      {
          get { return _title; }
          set { if (_title != value) { _title = value; OnPropertyChanged("Title"); } }
      }
      private string _detail;
      public string Detail
      {
          get { return _detail; }
          set { if (_detail != value) { _detail = value; OnPropertyChanged("Detail"); } }
      }
      private bool _showDetails;
      public bool ShowDetails
      {
          get { return _showDetails; }
          set { if (_showDetails != value) { _showDetails = value; OnPropertyChanged("ShowDetails"); } }
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged(string propertyName)
      {
          if (PropertyChanged != null)
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
  }
  </code></pre>