使用带有Frame控件的Prism NavigationService赢得通用应用程序

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

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

一个类似的问题已经解决了: 注册导航服务到框架元素而不是页面 – WinRt Prism 2.0,但我不喜欢这个解决方案。

解决方案:在inheritance自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); }