视图导航棱镜
嘿伙计们,
我正在使用 Prism 4 来实现我的演示, 问题是我正在使用包含区域的视图,现在我想导航到同一范围下的视图的其他实例,因此我将视图的 KeepAlive 属性设置为 false,以便在导航中视图将从区域和新视图将会出现,但我不断收到区域名称已存在的异常。
如何在包含区域的同一视图的几个实例之间导航(当时内存中应该只有一个)
谢谢
埃兰
Hey guys,
I'm using prism 4 to implement my presentation,
the thing is that i'm using view that contains region,now I want to navigate to other instance of the view under the same scope so I set the KeepAlive property of the view to false so that in navigation the view will be removed from the region and the new view will appear ,but I'm keep getting region name already exist exception.
how can I navigate between few instances of the same view that contain region (only one should be in memory at the time)
Thanks
Eran
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想将作用域 RegionManager 与导航一起使用。您看到区域名称已存在异常的原因是因为同一 RegionManager 中有多个具有相同名称的区域。
默认情况下,PRISM 不支持带导航的作用域 RegionManager,但如果您使用自定义 RegionBehaviors,则添加此功能非常容易。本质上,您需要做的是创建一个接口,然后在视图或视图模型上实现该接口。然后,创建一个 RegionBehavior 来查找该接口,如果满足要求,则为该视图创建一个新的 RegionManager 实例。
界面可能如下所示:
RegionBehavior 可能如下所示:
不要忘记您需要注册 RegionBehavior。我建议将其注册为引导程序中的默认 RegionBehavior,如下所示:
It sounds like you want to use a scoped RegionManager with navigation. The reason you're seeing the region name already exists exception is because you have more than one region with the same name in the same RegionManager.
By default, PRISM doesn't support scoped RegionManagers with navigation, but it's pretty easy to add this in if you use custom RegionBehaviors. Essentially what you need to do is create an interface and then implement that interface on your view or view model. Then, create a RegionBehavior that looks for that interface and, if it meets the requirements, creates a new RegionManager instance for that view.
Here's what the interface might look like:
And here's what the RegionBehavior might look like:
And don't forget that you'll need to register your RegionBehavior. I suggest registering it as a default RegionBehavior in the bootstrapper like so: