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

时间:2016-03-03 15:17:46

标签: c# xamarin xamarin.ios xamarin.forms portable-class-library

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没有显示?我怎么能让它显示出来?

1 个答案:

答案 0 :(得分:6)

据我了解,您告诉ActivityIndicator展示自己,然后导航到另一个页面。并且新页面没有ActivityIndicator。我建议您使用OnAppearing BookPage方法进行艰苦的操作。

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

    activityIndicator.IsVisible = true;

    // Some hard operations

    activityIndicator.IsVisible = false;
}

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