同一区域内的棱镜视图切换

发布于 2024-07-22 16:29:23 字数 158 浏览 4 评论 0原文

我有一个名为“ActiveModule”的区域,想要在不同的视图中重新使用它,例如,您按下搜索按钮,我会在其中显示搜索视图,等等。

我可以 ATM 做到这一点的唯一方法是停用该区域中的所有活动视图,然后激活我喜欢的视图,这有点脏,是否有“viewManager”或类似的东西我可以使用?

I have a region named "ActiveModule" and want to re-use it with different views, for example you press the search button and I show the search view in there, etc. etc.

The only way I can ATM do that is to deactivate all the active views in that region and then activate the view I like, this is a bit dirty, is there a "viewManager" or something similar I can use?

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

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

发布评论

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

评论(5

早乙女 2024-07-29 16:29:23

如果您的区域是 ContentControl 或派生自 ContentControl,则一次只能有一个活动视图,并且您只需激活该区域上的搜索视图。

If your region is a ContentControl or derives from ContentControl, then there can only be one active view at a time, and you only need to activate the search view on the region.

两人的回忆 2024-07-29 16:29:23

您是否考虑过使用一种能够显示多个视图的 contentControl?
例如,您可以像这样使用 TabControl:

<TabControl Name="MainRegion" Regions:RegionManager.RegionName="MainRegion"/>

您现在可以向该区域添加多个视图。 使用 Prism 中的 INavigationAwareIActiveAware 接口能够在视图上进行导航(激活它们、找到正确的视图等)。

Did you consider to use a type of contentControl that is able to show multiple views?
For example you can use a TabControl like this:

<TabControl Name="MainRegion" Regions:RegionManager.RegionName="MainRegion"/>

You can now add more than one view to the region. Use INavigationAware and IActiveAware interfaces from Prism to be able to do navigation on the views (activate them, find the correct view etc.).

南…巷孤猫 2024-07-29 16:29:23

如果您使用的是IRegionManager,则可以删除您识别的所有类型的视图,然后添加您自己的视图。

    foreach (var view in _regionsManager.Regions["MyRegion"].Views.ToArray())
    {
        if (view is MyType ||
            view is MyOtherType)
            _regionsManager.Regions["MyRegion"].Remove(view);
    }

    _regionsManager.AddToRegion("MyRegion", typeof(MyView));

它绝不是理想的,但它确实有效。 :)

If you are using a IRegionManager, you can remove all of the views whose types you recognize and then add your own.

    foreach (var view in _regionsManager.Regions["MyRegion"].Views.ToArray())
    {
        if (view is MyType ||
            view is MyOtherType)
            _regionsManager.Regions["MyRegion"].Remove(view);
    }

    _regionsManager.AddToRegion("MyRegion", typeof(MyView));

Its by no means ideal, but it works. :)

偷得浮生 2024-07-29 16:29:23

据我所知,您正在做的事情是唯一的方法,理论上在 SCSF 中,最顶层的视图是由框架激活的。 您可以创建自己的 ViewManager 或等效的 ShowViewService 来完成此操作。 事实上,这就是我所做的!

To my knowledge what you are doing is the only way, theoretically in SCSF the top most view was activated by the framework. You could create ur own ViewManager or a ShowViewService equivalent to get this done. MAtter of fact, thats what i have done!

哆啦不做梦 2024-07-29 16:29:23

不确定您如何布局框架,但如果您使用与导航相关的框架,您只需调用

regionManager.RequestNavigate(RegionNames.MainContentRegion, new Uri("your target view" + parameters, UriKind.Relative));

上面的行即可停用该区域中的其他视图。

否则,如果您确实进行视图发现或视图注入,则可以使用此处的方法

region.Activate(view);

Not sure how you laid out your framework but if you are using navigation related framework you can simply call

regionManager.RequestNavigate(RegionNames.MainContentRegion, new Uri("your target view" + parameters, UriKind.Relative));

the above line will take care of deactivating other views in the region.

Otherwise if you do view discovery or view injection you can use the approach here

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