gpt4 book ai didi

c# - Prism 模块在 View 中有自己的区域

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:15 24 4
gpt4 key购买 nike

我正在使用 Silverlight 5 (MefBootstrapper) 在 Prism V4.1 中练习。不幸的是我找不到这样的情况的实现:

  1. 我的 Shell.xaml 中有 2 个区域。
  2. 我的模块(在 modulescatalog.xaml 中描述的 xap 文件)(Module1 和 Module2)被注入(inject)到这个区域;
  3. 我在模块(例如模块 1)中的一个 View 有它自己的区域。

我想使用 prism 框架的强大功能将另一个模块注入(inject)到这个 Module1 View 中。事实上,这个模块应该是一个小 Prism 应用程序,它有自己的模块,应该有可能将参数传递给 Module2 和其他模块。

有什么办法可以实现吗?

我的意思是:Module1 内部的 View 可以创建自己的区域,因此依赖模块可以将 View 注入(inject)该区域吗?

最佳答案

是的,为什么不呢?加载依赖模块后,只需将 View 注册到该区域即可。例如,您可以在依赖模块的 IModule.Initialize 方法中执行此操作:

public void Initialize()
{
regionManager.RegisterViewWithRegion("Module1RegionName", () => serviceLocator.GetInstance<DependentModuleView>());
}

然后您可以导航到此 View 或在注册后随时激活它。

regionManager.RequestNavigate("Module1RegionName", new Uri("DependentModuleView", UriKind.Relative));

//or resolve the view and activate it
var view = serviceLocator.GetInstance<DependentModuleView>();
var region = regionManager.Regions["Module1RegionName"];
region.Activate(view);

至于模块之间的通信,您有几种选择。阅读Communicating Between Loosely Coupled Components获取更多信息。

关于c# - Prism 模块在 View 中有自己的区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12586810/

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