使用带有框架控件的Prism NavigationService赢得通用应用程序 [英] Win universal app using Prism NavigationService with Frame control
问题描述
我们如何将Prism NavigationService与Frame控件结合在一起? 我有一个包含框架的主页.首先,我必须导航到主页,之后要更改NavigationSerices,以便它使用框架而不是整个页面.
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.
因此,我需要Windows-Store-App-Prism框架中Prism 5.0中的区域.
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.
推荐答案
解决方案:在继承自MvvmAppBase的App.xaml.cs中添加:
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);
}
这篇关于使用带有框架控件的Prism NavigationService赢得通用应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!