告诉 ActivityIndi​​cator 显示自己,然后导航到另一个页面

Tell ActivityIndicator to show yourself and then navigate to another page

Xamarin.Forms项目中,我试图告诉ActivityIndicator展示你自己然后导航到另一个页面

activityIndicatorObject = new ActivityIndicator()
                {
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    Color = Color.Red,
                    IsVisible = false,
                    IsRunning = false,
                    IsEnabled = false,
                    BindingContext = this,
                };
ViewBookButton = new Button{ Text = "view book" };
ViewBookButton.Clicked += ViewBook;
protected void ViewBook(Object sender,EventArgs e)
            {
                //Go To View Book Page 
                activityIndicatorObject .IsVisible = true;
                activityIndicatorObject .IsRunning = true;
                activityIndicatorObject .IsEnabled = true;
                activityIndicatorObject .SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");
                this.IsBusy = true;
                Navigation.PushAsync(new BookPage());
                this.IsBusy = false;
            }

ActivityIndicator 没有显示?我怎样才能让它显示出来?

据我所知,您告诉 ActivityIndicator 显示您自己,然后导航到另一个页面。并且新页面还没有拥有 ActivityIndicator。我想建议你在BookPageOnAppearing方法中进行硬操作。

protected override void OnAppearing()
{
    base.OnAppearing();

    activityIndicator.IsVisible = true;

    // Some hard operations

    activityIndicator.IsVisible = false;
}

或使用绑定代替 activityIndicator.IsVisible = true;