gpt4 book ai didi

wpf - 在 Prism 中使用 ModuleManager 加载模块

转载 作者:行者123 更新时间:2023-12-04 14:53:22 25 4
gpt4 key购买 nike

这个问题也发布在 Prism's site on Codeplex .

我对按需加载模块有点迷茫,希望你们能不吝赐教。我正在使用 v2 #7 .

这是我想要完成的事情:

1) I have 2 regions - one for buttons that instantiate the modules (MenuRegion), another to show the modules (MainRegion). Only one module is to be visible at a time in MenuRegion.
2) Modules are to be found in a directory
3) The MenuModule module is associated with MenuRegion and is to create buttons showing the module names. When one of the buttons is clicked, the corresponding module is to be loaded and displayed in MainRegion.
4) Behavior:
    a) ModuleA button is clicked and ModuleA is displayed. User enters data in ModuleA and data is left in an unsaved state.
    b) ModuleB button is clicked and ModuleB is displayed. User enters data in ModuleB and data is left in an unsaved state.
    c) ModuleA button is click and ModuleA is displayed with the information previously entered.



如果我的假设有误,请纠正我,并请给我其他建议:

1) MainRegion should be a ContentControl, so only one module is visible at a time.
2) I think I need to enumerate the "GrouplessModules" of my Catalog to get the ModuleInfo for the modules available in the directory
3) To load the module I think I need to call myModuleManager.LoadModule(moduleName)



最后,我的问题:

1) Should I have the moduleManager as a parameter in my MenuModuleView's constructor?
2) How do I get the catalog accessible from inside MenuModuleView, in order to enumerate the available modules?
3) From MenuModuleView, as I enumerate through the modules, I create the buttons, assigning the ModuleInfo to the button's Tag property. This way, I have only one click event to load the module. Is this correct? It smells a bit work-aroundish to me...



非常感谢你的帮助!!!

最佳答案

1) Should I have the moduleManager as a parameter in my MenuModuleView's constructor?



从技术上讲,你可以。但实际上,如果您这样做,您仍然需要为您的 View 定义一个默认构造函数。否则,您的 View 将不适用于设计师。因此,我建议使用属性将依赖项传递给 UI 组件。

2) How do I get the catalog accessible from inside MenuModuleView, in order to enumerate the available modules?



您将依赖 Prism 的 IModuleEnumerator接口(interface)和依赖注入(inject)将负责将模块枚举器提供给您的 View 。假设您将 Prism 与 Unity 容器一起使用,则看起来像这样:
[Dependency]
public IModuleEnumerator ModuleEnumerator
{
get; set;
}

3) From MenuModuleView, as I enumerate through the modules, I create the buttons, assigning the ModuleInfo to the button's Tag property. This way, I have only one click event to load the module. Is this correct? It smells a bit work-aroundish to me..



我建议您让每个按钮发出相同的 WPF 命令,而是分配 ModuleInfoButtonCommandParameter属性(property)。同样,Prism 有基础设施来帮助您在复合场景中干净利落地完成此操作。见 DelegateCommand类(class)。

最后一点,请注意,虽然您可能能够延迟加载模块,但您将无法卸载它们。为此,您需要 AppDomain隔离,这是另一锅鱼。

关于wpf - 在 Prism 中使用 ModuleManager 加载模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/379751/

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