棱镜导航到另一个视图

本文关键字:视图 另一个 导航 棱镜 | 更新日期: 2023-09-27 18:15:56

我有一个主窗口,它只包含用于显示其他视图的区域:

<ContentControl Grid.Row="1" prism:RegionManager.RegionName="ContentRegion"/>

我想做的是,当我的MainWindowViewModel加载时,立即导航到MainPageViewModel

我已经尝试实现接口INavigationAware,如:

    public void OnNavigatedTo(NavigationContext navigationContext)
    {
        _regionManager.RequestNavigate("ContentRegion", App.Experiences.DetailPage.ToString());
    }
    public bool IsNavigationTarget(NavigationContext navigationContext)
    {
        return true;
    }
    public void OnNavigatedFrom(NavigationContext navigationContext)
    {
        _regionManager.RequestNavigate("ContentRegion", App.Experiences.DetailPage.ToString());
    }

但是即使我在上面设置了断点,它们也不会被执行。

我做错了什么?

编辑

也许我需要改变我的Bootstrapper逻辑?下面是它的样子:

public class Bootstrapper: UnityBootstrapper
{
    protected override System.Windows.DependencyObject CreateShell()
    {
        return Container.TryResolve<MainWindow>();
    }
    protected override void InitializeShell()
    {
        Application.Current.MainWindow.Show();
    }
    protected override void ConfigureContainer()
    {
        base.ConfigureContainer();
        Container.RegisterType(typeof(IDataRepository), typeof(DataRepository), null,new Microsoft.Practices.Unity.ContainerControlledLifetimeManager());

        Container.RegisterTypeForNavigation<MainPage>(App.Experiences.MainPage.ToString());
        Container.RegisterTypeForNavigation<DetailPage>(App.Experiences.DetailPage.ToString());

    }
}

棱镜导航到另一个视图

我必须编辑我的Bootstrapper逻辑,如下所示:

    protected override void InitializeShell()
    {
        Application.Current.MainWindow.Show();
        Prism.Regions.IRegionManager newRegion = Container.TryResolve<Prism.Regions.IRegionManager>();
        newRegion.RequestNavigate("ContentRegion", App.Experiences.MainPage.ToString());
    }