Centering a ListView in Xamarin Forms

As it took me way more time than expected, and more people on the Xamarin Forums were asking how to do this, here is a quick guide to center a ListView (horizontally and vertically) in Xamarin Forms.

The most important point is that you have to give the ListView a HeightRequest value. If you do not do this, the layout will not behave like you expect.

The XAML looks like this:

<StackLayout VerticalOptions="Center" HorizontalOptions="Center">
  <Label Text="Select Option" HorizontalTextAlignment="Center" />
  <ListView HeightRequest="500" ItemsSource="{Binding Divisions}" VerticalOptions="Center" HorizontalOptions="Center">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <Label Text="{Binding Description}" HorizontalTextAlignment="Center"/>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
</StackLayout>