我有一个使用Prism开发的Xamarin表单应用程序。 我在IOS中面临的问题是我无法从下面的方法导航到CreateAccount页面。但是相同的代码在UWP中可以正常工作。
protected async override void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync($"NavigationPage/LoginPage");
}
protected override void RegisterTypes(IContainerRegistry
containerRegistry)
{
containerRegistry.RegisterForNavigation<CreateAccount, CreateAccountViewModel>();
containerRegistry.RegisterForNavigation<LoginPage,LoginViewModel>();
containerRegistry.RegisterForNavigation<ForgotPassword>();
}
当我像下面这样替换上面的行时,正在发生导航,但未注册ViewModel。
containerRegistry.RegisterForNavigation<CreateAccount>();
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App(new iOSInitializer()));
return base.FinishedLaunching(app, options);
}
}
public class iOSInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
}
}
}
public class CreateAccountViewModel : BasePageViewModel,
INavigationAware
{
public static INavigationService _navigationService;
public CreateAccountViewModel(INavigationService navigationService)
: base(navigationService)
{
_navigationService = navigationService;
}
}
感谢您的帮助。
答案 0 :(得分:0)
解决方案:
尝试在NavigationPage
中注册RegisterTypes
。
protected override void RegisterTypes(IContainerRegistry
containerRegistry)
{
containerRegistry.RegisterForNavigation<CreateAccount, CreateAccountViewModel>();
containerRegistry.RegisterForNavigation<LoginPage, LoginViewModel>();
containerRegistry.RegisterForNavigation<ForgotPassword>();
//add
containerRegistry.RegisterForNavigation<NavigationPage>();
}