Prism 6 区域管理器 RequestNavigate 无法导航某些区域 [英] Prism 6 Region Manager RequestNavigate fails to navigate for some regions

查看:145
本文介绍了Prism 6 区域管理器 RequestNavigate 无法导航某些区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,其中定义了多个用于注入视图的 Prism 区域.我决定使用 Prism 视图导航来处理切换我的SelectedMenuContentRegion"基于用户操作(如下所示),但我遇到了问题.我确定问题出在我的使用上,但我一直无法弄清楚我做错了什么.我有以下包含自定义 WPF 控件的用户控件.

I have a user control where I have multiple Prism regions defined for injecting views. I decided to use the Prism view navigation for dealing with switching my "SelectedMenuContentRegion" based on user actions (as shown below) and I have run into a problem. I am sure the problem is with my usage, but I have not been able to figure out what I am doing wrong. I have the following user control which contains a custom WPF control.

<Grid>
  <commonwpfcontrols:NavigationPane Background="{StaticResource SecondaryColorBrush}" IsExpanded="False" MenuItems="{Binding MenuItems}">
     <commonwpfcontrols:NavigationPane.Content>
        <ContentControl prism:RegionManager.RegionName="MapRegion"/>
     </commonwpfcontrols:NavigationPane.Content>
     <commonwpfcontrols:NavigationPane.SelectedMenuContent>
        <ContentControl prism:RegionManager.RegionName="SelectedMenuContentRegion"/>
     </commonwpfcontrols:NavigationPane.SelectedMenuContent>
  </commonwpfcontrols:NavigationPane>

  <Grid>
     <ContentControl prism:RegionManager.RegionName="ApplicationOverlay"/>
  </Grid>

定义了 3 个区域.如果我做标准

There are 3 regions defined. If I do the standard

mRegionManager.RegisterViewWithRegion("SelectedMenuContentRegion", () => mUnityContainer.Resolve<MapSettingsView>());

但是,如果我像下面这样注册导航视图,它会按预期工作:

It works as expected, however, if I register the view for navigation like the following:

mUnityContainer.RegisterTypeForNavigation<MapSettingsView>();

然后尝试稍后导航

mRegionManager.RequestNavigate("SelectedMenuContentRegion ", "MapSettingsView", NavigationComplete);

失败了.我在调试器中注意到区域管理器的区域列表中只有ApplicationOverlay"区域.因此,我将导航到的区域更改为 ApplicationOverlay 区域作为测试,并且它起作用了.我正在通过依赖注入获取区域管理器.关于为什么区域经理不知道其他已定义区域的任何线索?

It fails. I Noticed in the debugger that the region manager only had the "ApplicationOverlay" region in it's list of regions. So, I changed the region that I was navigating to, to the ApplicationOverlay region as a test, and it worked. I am getting the region manager through dependency injection. Any clue as to why the other defined regions are not known to the region manager?

更新由于需要更详细的信息,我创建了一个小的独立示例来显示失败的导航.Prism 导航示例

Update Since more detailed information is required, I created a small standalone sample that shows the failed navigation. Prism Navigation Sample

推荐答案

这取决于您使用的自定义控件.导航窗格可能不属于可视化树(或初始化)的一部分,直到稍后.RegisterViewWithRegion 可以工作的原因是因为它会在注入之前等待区域被实现.所以这告诉我您正在尝试在区域初始化之前进行导航.

This depends on the custom control you are using. It is possible that the navigation panes at not part of the visual tree (or initialized) until later. The reason the RegisterViewWithRegion would work is because it waits until the region have been realized before injecting. So this tell me that you are trying to navigate before the regions have been initialized.

更新:感谢提供示例,它有助于解决问题.老实说,我没有花任何时间去弄清楚为什么它不起作用,而是我只是让它起作用.你所要做的就是给你的区域一个 x:Name,然后使用代码中的附加属性设置区域管理器:

UPDATE: Thanks for the sample, it helps repo the problem. Honestly, I didn't spend any time trying to figure out why it wasn't working, but instead I just got it to work. All you have to do it give your regions an x:Name, and then set the region manager using the attached property in code:

<ContentControl x:Name="_rightContents" />

然后在代码隐藏中:

public MainWindow(IRegionManager regionManager)
{
    InitializeComponent();
    RegionManager.SetRegionManager(_rightContents, regionManager);
}

这篇关于Prism 6 区域管理器 RequestNavigate 无法导航某些区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆