如何激活某个区域的下一个或最后一个视图?

发布于 2025-01-08 14:27:59 字数 778 浏览 1 评论 0原文

在我的应用程序中,我使用 Prism,它通过发现(Unity)加载三个模块。

当模块加载时,它们会在“TopLeftRegion”区域中注册每个视图。

我正在尝试执行模块视图的导航。我的意思是,创建 BeforeNext 方法,可以在其中激活(或 ["TopLeftRegion"].Activate(..))当前视图那个地区。

例如,假设我有:

|_ModuleA
|
|_ModuleB
|
|_ModuleC

如果我当前的视图是 ModuleA,如果我按 Next,则必须显示 ModuleB,如果我按 之前必须显示该区域中的 ModuleA

我正在观察房产:

regionManager.Regions["TopLeftRegion"].Views

但我不知道该怎么做。属性View 不允许访问数据并移入其中。

这是一个简单的项目,我试图在 ShellViewModel 中创建该方法,但我不明白。我该如何导航每个模块?

http://www.mediafire.com/?urnrwkrb29​​osrle

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?

http://www.mediafire.com/?urnrwkrb29osrle

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

非要怀念 2025-01-15 14:27:59

Prism 并不假设一个区域中只有一个活动视图,因此 Region 类上没有任何属性使这一过程变得非常简单。但这并不太棘手。

RegionManager 类跟踪 ActiveViews 属性中哪些视图处于活动状态。它不跟踪哪一个视图处于活动状态。就您而言,您所在的区域仅支持一个活动视图,因此您只能找到该集合中的第一个视图。

另一个棘手的部分是在 Region.Views 集合中查找活动视图。下面我将 Region.Views 转换为列表,以便我可以使用 FindIndex 来定位该活动视图的索引。

    private void Next(object commandArg)
    {
        IRegion myRegion = _regionManager.Regions["TopLeftRegion"];
        object activeView = myRegion.ActiveViews.FirstOrDefault();  //Here we're trusting that nobody changed the region to support more than one active view
        List<object> myList = myRegion.Views.ToList<object>();      //Cast the list of views into a List<object> so we can access views by index

        int currentIndex =  myList.FindIndex(theView => theView == activeView);
        int nextIndex = (currentIndex + 1) % (myList.Count);        //Wrap back to the first view if we're at the last view
        object nextView = myList[nextIndex];
        myRegion.Activate(nextView);  
    }

导航到上一个视图基本上是相同的,只不过您要从索引中减一而不是加一。

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.

    private void Next(object commandArg)
    {
        IRegion myRegion = _regionManager.Regions["TopLeftRegion"];
        object activeView = myRegion.ActiveViews.FirstOrDefault();  //Here we're trusting that nobody changed the region to support more than one active view
        List<object> myList = myRegion.Views.ToList<object>();      //Cast the list of views into a List<object> so we can access views by index

        int currentIndex =  myList.FindIndex(theView => theView == activeView);
        int nextIndex = (currentIndex + 1) % (myList.Count);        //Wrap back to the first view if we're at the last view
        object nextView = myList[nextIndex];
        myRegion.Activate(nextView);  
    }

Navigating to the previous view would be mostly the same, except you'd subtract one from the index instead of adding one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文