.NET MAUI
一种 Microsoft 开源框架,用于构建跨移动设备、平板电脑、台式机的原生设备应用程序。
52 个问题
我有一个 Shell
<ShellContent
ContentTemplate="{DataTemplate pages:StartupPage}"
Shell.FlyoutBehavior="Disabled"
Route="StartupPage"
Shell.FlyoutItemIsVisible="False" />
<ShellContent
ContentTemplate="{DataTemplate pages:LoginPage}"
Shell.FlyoutBehavior="Disabled"
Route="LoginPage"
Shell.FlyoutItemIsVisible="False" />
<ShellContent
ContentTemplate="{DataTemplate pages:NoInternetPage}"
Shell.FlyoutBehavior="Disabled"
Route="NoInternetPage"
Shell.FlyoutItemIsVisible="False" />
<FlyoutItem
FlyoutDisplayOptions="AsMultipleItems"
Route="WelcomePage">
<ShellContent
Title="Welcome"
ContentTemplate="{DataTemplate pages:WelcomePage}" />
<ShellContent
Title="Join meeting"
ContentTemplate="{DataTemplate pages:JoinMeetingPage}" />
<ShellContent
Title="Manage Course"
ContentTemplate="{DataTemplate pages:ManageCoursePage}" />
<ShellContent
Title="New Lecture"
ContentTemplate="{DataTemplate pages:NewLecturePage}" />
<ShellContent
Title="New Test"
ContentTemplate="{DataTemplate pages:NewTestPage}" />
<ShellContent
Title="Schedule lecture"
ContentTemplate="{DataTemplate pages:ScheduleLecturePage}" />
<ShellContent
Title="Schedule test"
ContentTemplate="{DataTemplate pages:ScheduleTestPage}" />
<ShellContent
Title="Assigned courses"
ContentTemplate="{DataTemplate pages:NotificationsPage}" />
</FlyoutItem>
</Shell>
第一页,是startupPage
private readonly StartupPageViewModel startupPageViewModel;
public StartupPage(StartupPageViewModel startupPageViewModel) {
InitializeComponent();
this.startupPageViewModel = startupPageViewModel;
BindingContext = startupPageViewModel;
}
protected override async void OnAppearing() {
base.OnAppearing();
await startupPageViewModel.CheckInternet();
}
}
这是对应的 ViewModel
public class StartupPageViewModel(IAppService appService, IConnectivity connectivity) : BaseViewModel {
public async Task CheckInternet() {
if(connectivity.NetworkAccess is not NetworkAccess.Internet) {
await appService.NavigateTo($"//{nameof(NoInternetPage)}");
} else {
await appService.NavigateTo($"//{nameof(LoginPage)}");
}
}
}
和 App 中的方法
public App(AppShell shell) {
InitializeComponent();
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(Constants.LICENSE);
MainPage = shell;
}
}
但是我得到了错误
Pending Navigations still processing 此问题整理于:https://learn.microsoft.com/en-us/answers/questions/1608720/login-flow-with-intrnet-check
你好,
Pending Navigations still processing
这是 Shell 导航的已知问题,根据 Pending Navigations still processing exception when navigating to the page #17608 中的讨论,有多种方法可以解决它。
解决方法 1:
如果我添加
await Task.Delay1)
,它将可以正常运行。
解决方法2:
我只在 Windows 上遇到过同样的问题,我觉得 Task.Delay1) 解决方法有点肮脏,所以想出了这段代码:
if (DeviceInfo.Platform == DevicePlatform.WinUI)
{
AppShell.Current.Dispatcher.Dispatch(async () =>
{
await Shell.Current.GoToAsync($"//{nameof(DashboardPage)}");
});
}
else
{
await Shell.Current.GoToAsync($"//{nameof(DashboardPage)}");
}
如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。 注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。