gpt4 book ai didi

wpf - 初始化后如何激活/停用模块的 View ?

转载 作者:行者123 更新时间:2023-12-01 23:20:02 24 4
gpt4 key购买 nike

这与 WPF 或 Prism 的复合应用指南有关。

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

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

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

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

感谢您的帮助!

最佳答案

您实际上并没有激活该模块。您激活区域中的 View 。阅读此 article .

Initialize 方法只为任何模块调用一次。当您调用 LoadModule 时,您看到模块中的一个 View 被激活,我猜这是因为 Initilalize 方法正在向一个区域注册一个 View 。这将激活 View 。如果您有多个 View ,那么最后注册的将是事件 View 。

要激活 View ,您需要调用区域的 Activate 方法(假设注入(inject)了 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);

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

关于wpf - 初始化后如何激活/停用模块的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/360378/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com