首页 > 解决方案 > Navigate to new window in Prism WPF

问题描述

QUESTION 1

I know there is a way to open popup dialog with custom view using InteractionRequestTrigger, PopupWindowAction and InteractionRequest. But I am looking for solution like registering Window and WindowViewModel for navigation and call INavigationAsync.Navigate("SomeWindowUri", someParameters). It seems much simpler and cleaner solution. Does Prism support such approach?

QUESTION 2

I have main window (MainWindow) and new window (NewWindow) to be displayed from MainWindow. I am trying to display some view in region which is defined in NewWindow. When I use IRegionManager.RegisterViewWithRegion it works as expected. But when I display NewWndow and then call IRegionManager.RequestNavigate nothing happens. The method IRegionManager.RequestNavigate works as expected when region is in MainWindow. Is it my mistake or Prism cannot do navigation in separate window?

Here is an example: https://bitbucket.org/equo/prismregionnavigationtest.git It is modified example of Prism example for WPF: 17-BasicRegionNavigation. After opening new window there nothing happens when clicking on any button, but ViewA or ViewB should be displayed below. After uncommenting MainWindow1 in App.CreateShell method the window works as expected.

标签: wpfprism

解决方案


根据问题 1: Prism 团队正在开发新的对话服务,这正是我想要做的。https://github.com/PrismLibrary/Prism/pull/1682 它已经通过 prism 的预览版提供。

根据问题 2:要使其正常工作,需要创建作用域区域并将其附加到新创建的窗口。

_ScopedRegion = _RegionManager.CreateRegionManager();
RegionManager.SetRegionManager(newWindow, _ScopedRegion);

然后用它在新窗口中导航。

_ScopedRegion.RequestNavigate("NewRegion", "ViewA");

演示在这里: https ://bitbucket.org/equo/prismregionnavigationtest.git


推荐阅读