具有 Shell 个顶部导航的 ActivityIndi​​cator

ActivityIndicator with Shell top navigation

我有一个带有一些 ShellContent 的 shell 导航,员工菜单加载数据需要很长时间。我已经搜索添加ActivityIndi​​cator,但我不知道如何实现。

<Shell ..>
    <Shell.FlyoutHeader>

                <ActivityIndicator IsRunning="{Binding IsBusy}"
                                   IsVisible="{Binding IsBusy}"
                                   HorizontalOptions="Center"
                                   VerticalOptions="Center"
                                   Color="Black" />

    </Shell.FlyoutHeader>

<ShellContent x:Name="home"
Route="main"
ContentTemplate="{DataTemplate home:Dashboard}" />
</Shell>
<ShellContent x:Name="listEmp"
Route="Employees"
IsVisible="{Binding IsEmployees}"
ContentTemplate="{DataTemplate home:Employees}" />
</Shell>

有一个解决方案,我们更改 MenuItem 而不是 ContentTemplate:

 <MenuItem Command="{Binding LoadEmployeesCmd}" />

在 ViewModel 中:

        public ICommand LoadEmployeesCmd=> new Command(() => LoadEmployees());

        private async void LoadEmployees()
        {
            IsBusy = true;
            Routing.RegisterRoute(nameof(Views.Employees), typeof(Views.Employees));

          await Shell.Current.GoToAsync("//Employees");

            IsBusy = false;
            Shell.Current.FlyoutIsPresented = false;

        }

我正在寻找是否有不将 ShellContent 更改为 MenuItem 的解决方案,因为在 MenuItem 中没有 IsVisible...

您可以将 IsBusy 属性 与 AppShell 的 IsBusy 绑定,并在加载方法中更改 AppShell 的 is Busy,例如: AppShell.xmal.cs:

    public AppShell(){
    InitializeComponent();
    ...
    BindingContext=this;}

视图模型:

  private async void LoadEmployees()
    {
    AppShell.Current.IsBusy=true;//change the property

        Routing.RegisterRoute(nameof(Views.Employees), typeof(Views.Employees));

      await Shell.Current.GoToAsync("//Employees");

        AppShell.Current.IsBusy=false;
        Shell.Current.FlyoutIsPresented = false;

    }