shell 加载页面时显示ActivityIndicator

e7arh2l6  于 6个月前  发布在  Shell
关注(0)|答案(1)|浏览(53)

我有以下情况。
在登录页面上,

private async Task LoginAsync()
{
    ...............
    IsBusy = true;
    ...............
    await Shell.Current.GoToAsync($"//{nameof(Pending)}");
    ..............
    finally
        {
            IsBusy = false;
        }
}

字符串
所以我从登录到等待状态。
正在等待中.xaml::

<ActivityIndicator
        x:Name="isVeryBusy"
        Grid.Row="0"
        Grid.Column="0"
        Grid.RowSpan="3"
        Grid.ColumnSpan="4"
        HorizontalOptions="FillAndExpand"
        IsRunning="{Binding IsBusy}"
        IsVisible="{Binding IsBusy}"
        VerticalOptions="CenterAndExpand" />


在Pending xaml.cs中:

protected override void OnAppearing()
    {
        try
        {
            base.OnAppearing();
            LoadData(viewModel);
        }
        .............           
    }


public static async void LoadData(Pending_VM viewModel)
    {
        await viewModel.GetMyObjects();
    }


最后,在Pending的ViewModel中,我有:

[RelayCommand]
public async Task GetMyObjects()
{
    if (IsBusy)
    {
        return;
    }

    try
    {           
        IsBusy = true;
        //Some slow running code goes here (about three secs)           
    }
    catch (Exception ex)
    {
        ErrorHandling.HandleError(ex);
    }
    finally
    {
        IsBusy = false;                
    }
}


我想在这里做的是显示ActivityIndicator旋转,直到我的数据加载完成。
但事情并不是这样的,我盯着登录页面,它似乎被冻结了,大约三秒钟,然后,繁荣,待定页面显示出来,装备齐全。
我应该在这里做什么来显示ActivityIndicator,而壳到另一个页面?
谢谢你!亚历克斯

c8ib6hqw

c8ib6hqw1#

请为xdc方法添加await。例如:

protected async override void OnAppearing()
    {
        try
        {
            base.OnAppearing();
            await LoadData(viewModel);
        }
        .............           
    }

字符串

相关问题