Why Activity Indicator Not working In Xamarin.forms?

十年热恋 提交于 2019-12-03 16:07:18

None of the code between this.IsBusy=true; and this.IsBusy=false; is asynchronous. So what is happening is that you enable the indicator but then continue to do work on the main thread and then disable the indicator before the UI has a chance to update.

To fix this, you would need to put appClient.UpdateInfo(user) into an async code block (along with the PushAsync and disabling of activity indicator and probably some of the other code). If you don't have an async version of UpdateInfo() then you can push it off into a background thread... assuming whatever work it does is actually safe for running in a background thread.

ProcessToCheckOut.Clicked += (object sender, EventArgs e) =>
{
    this.IsBusy = true;
    var id = CustomersPage.ID;
    Task.Run(() => {
        UserUpdateRequest user=new UserUpdateRequest();
        user.userId = id;
        appClient.UpdateInfo(user);
        Device.BeginInvokeOnMainThread(() => {
            this.IsBusy = false;
            Navigation.PushAsync(new CheckoutShippingAddressPage(appClient));
        });
    });
};

Note that I also used Device.BeginInvokeOnMainThread() to marshal execution back to the main thread once the background work is done. This isn't always necessary but it is good practice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!