问题
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