如何激活某个区域的下一个或最后一个视图?
在我的应用程序中,我使用 Prism,它通过发现(Unity)加载三个模块。
当模块加载时,它们会在“TopLeftRegion”区域中注册每个视图。
我正在尝试执行模块视图的导航。我的意思是,创建 Before
和 Next
方法,可以在其中激活(或 ["TopLeftRegion"].Activate(..)
)当前视图那个地区。
例如,假设我有:
|_ModuleA
|
|_ModuleB
|
|_ModuleC
如果我当前的视图是 ModuleA
,如果我按 Next
,则必须显示 ModuleB
,如果我按 之前必须显示该区域中的
ModuleA
。
我正在观察房产:
regionManager.Regions["TopLeftRegion"].Views
但我不知道该怎么做。属性View
不允许访问数据并移入其中。
这是一个简单的项目,我试图在 ShellViewModel 中创建该方法,但我不明白。我该如何导航每个模块?
In my application, I'm using Prism and it loads three modules by discovery (Unity).
When the modules are loading, they register each View in "TopLeftRegion" region.
I'm trying to perform a navigation of module views. I mean, create Before
and Next
methods where can activate (or ["TopLeftRegion"].Activate(..)
) the current view in that region.
For example, Imagine I have:
|_ModuleA
|
|_ModuleB
|
|_ModuleC
If my current view is ModuleA
, if I press Next
, must show ModuleB
, if I press Before
must show ModuleA
in that region.
I was watching the property:
regionManager.Regions["TopLeftRegion"].Views
But I don't know to do this. The property View
doesn't allow to access to the data and move into it.
Here's a simple project, I'm trying to create that method in ShellViewModel and I don't get it. How can I do to navigate each module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Prism 并不假设一个区域中只有一个活动视图,因此 Region 类上没有任何属性使这一过程变得非常简单。但这并不太棘手。
RegionManager 类跟踪 ActiveViews 属性中哪些视图处于活动状态。它不跟踪哪一个视图处于活动状态。就您而言,您所在的区域仅支持一个活动视图,因此您只能找到该集合中的第一个视图。
另一个棘手的部分是在 Region.Views 集合中查找活动视图。下面我将 Region.Views 转换为列表,以便我可以使用 FindIndex 来定位该活动视图的索引。
导航到上一个视图基本上是相同的,只不过您要从索引中减一而不是加一。
Prism doesn't assume that there is only one active view in a region, so there aren't any properties on the Region class that make this super simple. But it isn't too tricky.
The RegionManager class tracks which views are active in the ActiveViews property. It isn't tracking which one view is active. In your case, your region only supports one active view, so you can just find the first view in that collection.
The other tricky part is finding the active view in the Region.Views collection. Below I cast the Region.Views as a List so that I could use FindIndex to locate the index of that active view.
Navigating to the previous view would be mostly the same, except you'd subtract one from the index instead of adding one.