Xamarin.Forms - how to absolutely center an element on the page?

Viewed 20816

I have a login page using a StackLayout for the content (username, password, login button). After the user clicks the login button, I want a "loading" block set in the absolute center of the page, on top of the existing StackLayout content. For some annoying reason, this is not straightforward. It seems like a simple, common thing to do - how is this done?

2 Answers

To center an ActivityIndicator maybe you can try this Grid tip:

<ContentPage.Content>
    <Grid>
        <StackLayout>
            <Label Text="All content view in this StackLayout :D" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" />
        </StackLayout>
        <ActivityIndicator
            Color="#006699"
            HorizontalOptions="CenterAndExpand"
            VerticalOptions="CenterAndExpand"
            IsVisible="True"
            IsRunning="True" />
    </Grid>
</ContentPage.Content>

enter image description here


There is a good sample project that looks like this:

enter image description here enter image description here

Related