初始化后如何激活/停用模块的视图?

发布于 2024-07-09 23:52:21 字数 411 浏览 8 评论 0原文

这与 WPF 或 Prism 的复合应用程序指南相关。

我的 shell 中有一个“MainRegion”。 我的各种模块将被加载到这个主要区域中。 我可以在菜单中填充可用模块的列表并选择它们进行加载。 单击菜单时,我这样做:

var module = moduleEnumerator.GetModule(moduleName);
moduleLoader.Initialize(new[] { module });

第一次一切正常,因为执行了模块的Initialize()方法,但是在初始化Module1、Module2和Module3之后​​,当我再次单击加载Module2时没有任何反应。

我的问题:在执行模块的初始化方法后,如何按需激活模块?

感谢您的帮助!

This relates to Composite Application Guidance for WPF, or Prism.

I have one "MainRegion" in my shell. My various modules will be loaded into this main region. I can populate a list of available modules in a menu and select them to load. On the click of the menu I do:

var module = moduleEnumerator.GetModule(moduleName);
moduleLoader.Initialize(new[] { module });

At the first time all works ok, because the Initialize() methods of the modules are executed, but after Module1, Module2 and Module3 are initialized, nothing happens when I click to load Module2 again.

My question: how can I activate a module on demand, after its initialize method has been executed?

Thank you for your help!

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

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

发布评论

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

评论(4

天冷不及心凉 2024-07-16 23:52:22

您应该有一个属于您所在区域的 ContentControl。 然后您需要将所有模块添加到该区域。 当您单击菜单时,您应该使用该区域的 Activate(...) 方法来激活特定模块。

You should have a ContentControl that will be your region. Then you will need to add all your modules to this region. When you click on the menu you should use Activate(...) method of the region in order to activate the particular module.

回忆那么伤 2024-07-16 23:52:22

这是否意味着当您激活模块时,可能与其重叠的其他模块将设置为 Visibility.Collapsed ?

Does this mean when yuou activate module, then other modules that may be overlapped by it are set to Visibility.Collapsed?

人生百味 2024-07-16 23:52:21

您实际上并未激活该模块。 您激活某个区域中的视图。 阅读这篇文章

对于任何模块,Initialize 方法仅调用一次。 事实上,当您调用 LoadModule 时,您会看到模块中的视图被激活,我猜这是因为 Initilalize 方法正在向区域注册视图。 这将激活视图。 如果您有多个视图,则最后注册的视图将是活动视图。

要激活视图,您需要调用区域的 Activate 方法(假设注入了 IUnityContainer 和 IRegionManager)...

// Get a view from the container.
var view = Container.Resolve<MyView>();

// Get the region.
var region = RegionManager.Regions["MyRegion"];

// Activate the view.
region.Activate(view);

根据区域控件的类型,这将替换现有的视图或添加到其中。

You don't actually activate the module. You activate a view in a region. Take a read of this article.

The Initialize method is only called the once for any module. The fact that you are seeing a view in the module being activated when you call LoadModule I would guess is due to the fact that the Initilalize method is registering a view with a region. This will activate the view. If you had more than one view then the last registered would be the active one.

To Activate a view you need to call the Activate method of the region (assuming an injected IUnityContainer and IRegionManager)...

// Get a view from the container.
var view = Container.Resolve<MyView>();

// Get the region.
var region = RegionManager.Regions["MyRegion"];

// Activate the view.
region.Activate(view);

Depending on the type of region control this will either replace the view that is there or add to it.

冰雪之触 2024-07-16 23:52:21

您可以通过调用Regions的Remove方法来删除View。

public void RemoveViewFromRegion(string viewName, string regionName, object defaultView)
    {
      IRegion region = regionManager.Regions[regionName];
      object view = region.GetView(viewName);
      region.Remove(view);
      region.Activate(defaultView); 
    }

You can remove a View by calling Regions's Remove method.

public void RemoveViewFromRegion(string viewName, string regionName, object defaultView)
    {
      IRegion region = regionManager.Regions[regionName];
      object view = region.GetView(viewName);
      region.Remove(view);
      region.Activate(defaultView); 
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文