棱镜模块在视图中有自己的区域

时间:2012-09-25 16:03:18

标签: c# silverlight prism-4

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

  1. 我的Shell.xaml中有2个区域。
  2. 我的模块(modulescatalog.xaml中描述的xap文件)(Module1和Module2)注入了这些区域;
  3. 我在模块中的一个观点(例如Module1)有自己的区域。
  4. 我想使用prism框架的强大功能为这个Module1 View注入另一个模块。事实上,这个模块应该是一个小棱镜应用程序,它有自己的模块,应该有可能将params传递给Module2和其他模块。

    有没有办法实现这个?

    我的意思是:可以在Module1里面查看创建自己的Region,那么依赖模块可以将视图注入到这个Region中吗?

1 个答案:

答案 0 :(得分:2)

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

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

然后您可以导航到此视图,或在注册后立即激活它。

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以获取更多信息。

相关问题