我有一个带有一些ShellContent的shell导航,employees菜单加载数据花费了很多时间。我已经搜索添加ActivityIndicator,但我不知道如何实现。
<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;
}