简体   繁体   中英

Xamarin Portable OnAppearing() XAML page loading

i am using the Xamarin Forms Portable project and i am using the MVVM method. Right now I am stuck. I want to build a LOADING page. So when the (Custom) Page starts it must load a XAML page loading and when the Loading (call to a webservice) is done the XAML page loading must be set to visible = false.

I have the next code that wont work:

    protected override async void OnAppearing()
    {

        base.OnAppearing();

        var page = Navigation.PushAsync(new ActivityIndicatorPage());

        await Task.Delay(1000);

        BindingContext = new ProductViewModel(_ProductId);

    }

So how do i Call the 'ActivityIndicatorPage' Page and then set it to invisible after the 'BindingContext = new ProductViewModel(_ProductId);' call is done.

Thanx.

You need an AcitvityIndicator Just include this code in your xaml page where you want to show the loading and bind IsVisible property of StackLayout or whatever you choose as a container.

<StackLayout HorizontalOptions="Center" VerticalOptions="Center" IsVisible="{Binding IsLoading}">
    <ActivityIndicator Color="Red" IsRunning="true" />
</StackLayout>

then you can set its bindable property(or name of StackLayout whatever in your case) to true or false based on your background task completion for example: in your code behind or in viewModel you can do something like this

public async Task<bool> MyBackgroundTask(){
    IsLoading=true
    //your background task
    if(successful){
        IsLoading = false
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM