在 App.xaml.cs 或应用程序启动时在 ContentRegion(Prism) 中导航视图(登录)

Navigate a View(Login) in ContentRegion(Prism) at App.xaml.cs or on application Launch

我正在尝试在启动应用程序时在 Prism ContentRegion 中导航登录视图。

protected override void RegisterTypes(IContainerRegistry containerRegistry)
    {
        containerRegistry.RegisterForNavigation<Login>("Login");
    }
    protected override void OnInitialized()
    {
        base.OnInitialized();
        var regionManager = Container.Resolve<IRegionManager>();
        regionManager.RequestNavigate("ContentRegion", "Login");

    }

这似乎与 PrismLib 中的 to this issue 有关,其中导航还不能直接从 OnInitialized 完成。

作为解决方法,您可以做两件事,直到这个问题得到解决:

  • 使用 RegisterViewWithRegion
  • 或仅在 Window 激活后导航:
void Navigate(object sender, object args)
{
    regionManager.RequestNavigate("ContentRegion", "Login");

    Windows.UI.Xaml.Window.Current.Activated -= Navigate;
}

Windows.UI.Xaml.Window.Current.Activated += Navigate;