我是一个MAUI和移动的应用程序开发的新手,在最近的iOS更新后,我面临着从Xamarin.Forms到MAUI的强制迁移。问题是MAUI的模式导航并不像我期望的那样工作。代码如下:
private async void btnSend_Tapped(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//MainPage/TakePicture/SendPicture/OtpCheck");
if (Variables.CurrentPicture.Otp == 0)
{
....
}
await Shell.Current.Navigation.PopToRootAsync();
在我设置的OtpCheck页面的xaml中:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
...
x:Class="SkyObservers.Pages.OtpCheck"
Shell.PresentationMode="Modal">
我希望“if(Variables...”只有在OtpCheck页面关闭时才能到达,但它并不像这样工作。页面被加载,然后突然消失,因为“PopToRootAsync”立即到达。在Xamarin中。表单不能这样工作,所以我也尝试了await Navigation.PushModalAsync(new OtpCheck());
而不是await Shell.Current.GoToAsync("//MainPage/TakePicture/SendPicture/OtpCheck");
但结果是一样的
P.S.页面的路由(希望)在AppShell.xaml中正确注册:
<ShellContent Title="SkyObservers" ContentTemplate="{DataTemplate local:MainPage}" Route="MainPage" />
<ShellContent Title="Take New Picture" ContentTemplate="{DataTemplate pages:TakePicture}" Route="MainPage/TakePicture" />
<ShellContent Title="Send Picture" ContentTemplate="{DataTemplate pages:SendPicture}" Route="MainPage/TakePicture/SendPicture" />
<ShellContent Title="Check OTP" ContentTemplate="{DataTemplate pages:OtpCheck}" Route="MainPage/TakePicture/SendPicture/OtpCheck" />
在AppShell.xaml.cs中
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute("MainPage/TakePicture", typeof(TakePicture));
Routing.RegisterRoute("MainPage/TakePicture/SendPicture", typeof(SendPicture));
Routing.RegisterRoute("MainPage/TakePicture/SendPicture/OtpCheck", typeof(OtpCheck));
}
1条答案
按热度按时间8ftvxx2r1#
我已经通过在CommunityToolkit.Maui.Views.Popup中转换OtpCheck页面并等待结果来解决这个问题。页面的Xaml代码:
CodeBehind用于打开和等待弹出窗口的结果: