【问题标题】:Win universal app using Prism NavigationService with Frame control使用带有框架控件的 Prism NavigationService 赢得通用应用程序
【发布时间】:2015-08-01 21:51:52
【问题描述】:

如何将Prism NavigationService与Frame控件结合使用? 我有一个包含框架的主页。首先,我必须导航到主页,然后我想更改 NavigationSerices 以便它使用框架而不是整个页面。

所以我需要像 Windows-Store-App-Prism 框架中的 Prism 5.0 中的区域。

类似的问题已经解决了:Register Navigation Service to Frame Element and NOT the page - WinRt Prism 2.0 但我不喜欢这个解决方案。

【问题讨论】:

    标签: c# xaml navigation prism win-universal-app


    【解决方案1】:

    解决方法:在继承自 MvvmAppBase 的 App.xaml.cs 中添加:

    public static App Instance { get { return _instance; } }
    
    private Type Resolve(string name)
    {
        return Type.GetType(string.Format("{0}.Views.{1}Page", this.GetType().Namespace, name));
    }
    
    public void CreateNewNavigationFrame(Frame frame)
    {
        this.NavigationService = new FrameNavigationService(new FrameFacadeAdapter(frame), Resolve, this.SessionStateService);
    }
    

    在主页面(Frame所在页面)的构造函数中:

        public AppShellPage()
        {
            this.InitializeComponent();
            App.Instance.CreateNewNavigationFrame(this.frame);
        }
    

    【讨论】:

    • 目前这是 PRISM 中的一个问题。这个解决方案会在框架中引起一些问题,我尝试的所有其他解决方案都有类似的问题。所以我们必须在 PRISM 中等待 Win10 中的 Regions。
    • Regions for Prism UWP 已提上日程,但可能不会进入第一个 RTM 版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 2011-02-12
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多