gpt4 book ai didi

c# - 使用 MEF 从 shell 加载 Prism 模块 View

转载 作者:行者123 更新时间:2023-11-30 18:01:55 25 4
gpt4 key购买 nike

我有一个 shell 项目,它将我的 Bootstrap 中的模块加载到我的 shell 主视图中的选项卡控件中。

我刚刚在我的选项卡项上实现了一个关闭按钮,现在提出了一个问题,即如何从 shell 重新加载模块 View ?

尝试使用

moduleManager.LoadModule("ModuleA");

但这仅在模块首次加载时有效。当我调用上面的代码时,它加载并初始化模块,显示 View 。如果我再次关闭 View ,第二次尝试时它不会重新显示 View (我猜它不会重新初始化模块,因为它已经加载)。

所以,我虽然考虑过在我的 shell 中使用以下内容:

var moduleAView = ServiceLocator.Current.GetInstance<ModuleAView>();
regionManager.Regions["TabRegion"].Add(ModuleAView);
regionManager.Regions["TabRegion"].Activate(ModuleAView);

这种方法的问题是我的 shell 如何知道第 1 行中的 ModuleAView 类型?我没有对模块 A 的引用,也不想添加一个。我想到了 ModuleAView 将实现的一个通用接口(interface),它可以在模块和 shell 之间共享,但是当我尝试使用上述 ServiceLocator.GetInstance 方法时遇到了组合错误。

非常感谢您的帮助。

附言这是我试过的模块A模块代码。

[ModuleExport(typeof(ModuleA), InitializationMode = InitializationMode.OnDemand)]
[Module(ModuleName="ModuleA")]
public class ModuleA : IModule
{
private IRegionManager _regionManager;

[ImportingConstructor]
public ModuleA(IRegionManager regionManager)
{
this._regionManager = regionManager;
}

public void Initialize()
{
// add the search view to the region manager.
this._regionManager.RegisterViewWithRegion("TabRegion", typeof(Views.ModuleAView));
}
}

最佳答案

可能是在错误的轨道上思考这个问题。

我没有尝试从 shell 显示模块的 View ,而是从 moduleA 模块订阅的 shell 发布了一个事件。然后我可以决定在模块本身中显示什么 View 。

希望这对您有所帮助。

关于c# - 使用 MEF 从 shell 加载 Prism 模块 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8573376/

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