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>

Updating Windows 10 to the Creators Update

It was that time of the year again, another new version for Windows 10. Since the last update that gave me a lot of problems, I took the approach to wait a couple of weeks after it was out to see if any major problems emerged. As I’m a developer and I use both machines to developer software, I don’t like running into unexpected issues. I listen to Paul Thurrott a lot, he usually reports any widespread issues.

Nothing emerged after a couple of weeks, so I upgraded both machines to the Creators Update using the Update Tool. After using it for a while, I only came across 2 minor issues that have a workaround.

Issue 1: Both start options are reported as Windows 10

I use the Hanselman trick to switch between Windows 10 with Hyper-V enabled, and Windows 10 without Hyper-V. Hyper-V has to be disabled to run the Google Android Emulators. As I currently do a lot of Xamarin development, I need this a lot.

Luckily this is easily fixed again, thanks to a blog post by LocalJoost:

Re-enabling the Hanselman Trick

Issue 2: Right-Click ‘Run As Admin’ is broken

I wanted to fix Issue 1, opened up a Command Prompt by right-clicking and selecting Run As Admin, and… nothing happened. After googling a bit I came across another user having the same problem.

I was able to work around this problem in the following way:

  • Pin the cmd to the taskbar
  • Right-click on it while holding shift (so you get all the options), and select Properties
  • Click on Advanced, and then check ‘Run as Administrator’. Click OK
  • If you now use this shortcut, it will correctly ask you for admin privileges and start

If you have the same problem, you can upvote the issue in the Feedback Hub.