Win universal app using Prism NavigationService with Frame control

落爺英雄遲暮 提交于 2019-12-08 11:37:19

问题


How to us the Prism NavigationService combined with the Frame control? I have a main page which includes a Frame. First, I have to navigate to the main page, after that I want to change the NavigationSerices so that it uses the Frame instead of the whole page.

So I need something like regions from Prism 5.0 in the Windows-Store-App-Prism framework.

A similar problem was already solved: Register Navigation Service to Frame Element and NOT the page - WinRt Prism 2.0 but I don't like this solution.


回答1:


Solution: In the App.xaml.cs which inherits from MvvmAppBase add:

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);
}

In the constructor of the main page (the page where the Frame is):

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


来源:https://stackoverflow.com/questions/31766579/win-universal-app-using-prism-navigationservice-with-frame-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!