Prism模块化重装机制

发布于 2024-11-09 06:56:21 字数 709 浏览 0 评论 0原文

我正在尝试实现模块化,但遇到了一些复杂情况。我实现了一个名为 ModuleA 的模块,该模块在其初始化函数中显示新的 childWindow ;

public ModuleA()
{
   personViewModel = new PersonViewModel();
   detail = new ViewDetail(personViewModel);
}

public void Initialize()
{
   detail.Show();
}

我的问题是,由于缺少重新加载功能的机会,我无法再次显示视图。我的模块按需加载,我的意思是我想在用户单击按钮时加载模块,因此,我没有机会在开始时加载模块并通过其自身的事件控制其功能。然后我尝试像这样显示我的应用程序的视图;

private void ButtonModelA_Click(object sender, RoutedEventArgs e)
{
   this.moduleManager.LoadModule(MyBootstrapper.ModuleAName);
   ChildWindow detail = new ModuleA.ViewDetail(new ModuleA.ViewModel.PersonViewModel());
   detail.Show();
}

这样,加载模块就变得没有必要了。

有没有一种方法可以根据需要从中加载模块并多次显示其视图?

I'm trying to implement modularity and have some complications. I implemented one module which called ModuleA which shows new childWindow in its initialize function;

public ModuleA()
{
   personViewModel = new PersonViewModel();
   detail = new ViewDetail(personViewModel);
}

public void Initialize()
{
   detail.Show();
}

My problem is that i can't show the view again because of missing opportunity of reload function. My module loaded on demand, i mean that i want to load module when user clicks button so, i do not have a chance to load module at the beginning and control its functions from its own events. then i tried to show view from my application like that;

private void ButtonModelA_Click(object sender, RoutedEventArgs e)
{
   this.moduleManager.LoadModule(MyBootstrapper.ModuleAName);
   ChildWindow detail = new ModuleA.ViewDetail(new ModuleA.ViewModel.PersonViewModel());
   detail.Show();
}

in this way, loading module became unnecessary.

Is there a way to load module from out of it as on demand and show its view multiple times ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2024-11-16 06:56:21

我不太确定这在 Silverlight 中是如何工作的,但我认为这是对 Prism 的误解。

Prism是基于区域的。这意味着应用程序用户界面由声明为区域的 ContentControls(或其他支持区域的控件)组成。区域管理器现在将想要驻留在特定区域内的所有视图添加到该区域中。

模块只需告诉区域管理器在特定模块中实现的视图想要驻留在哪个区域内:

RegionManager.RegisterViewWithRegion( "RegionName", typeof( View ) );

如果特定区域当前不是用户界面的一部分,因为包含托管该区域的控件的视图不属于用户界面的一部分。作为用户界面本身的一部分,想要在该区域内重新调整的视图不能放置在该区域内。区域经理根本不了解该区域。要显示视图,您必须手动将托管区域的控件添加到用户界面。

另一种方法是手动将特定内容添加到区域中。使用这种方法,您不必将视图注册到区域管理器。因此,当区域经理发现该区域时,它仍然是空的。现在,您可以使用区域管理器将视图手动添加到区域中:

IRegion region = RegionManager.Regions["RegionName"];
region.Add( new View(), "ViewName" );

如果您想根据任何状态或用户操作将视图放置到区域中,则必须手动将视图添加到区域中。查看 Stock Trader 参考实施。它以非常简单的方式解释了如何将视图添加到由用户操作触发的区域。

I'm not quite sure how this works in Silverlight, but I think there is a misunderstanding of Prism.

Prism is based on regions. That means that the applications user interface consists of ContentControls (or other region capable controls) that state to be a region. The region manager now adds all views that want to reside inside a specific region into exactly this region.

The modules just have to tell the region manager inside which region the views implemented in the specific module wants to reside:

RegionManager.RegisterViewWithRegion( "RegionName", typeof( View ) );

If the specific region is currently not a part of the user interface, because the view that contains the control that hosts the region isn't part of the user interface itself, the view that wants to resied inside the region cannot be placed inside this region. The region manager just doesn't know of the region. To have the view shown you have to add the control that hosts the region to the user interface by hand.

Another way is to add a specific into a region by hand. Using this approach you don't have to register the view to the region manager. So when the region manager discovers the region it stays empty. Now you can add the view manually into the region using the region manager:

IRegion region = RegionManager.Regions["RegionName"];
region.Add( new View(), "ViewName" );

If you want to place views into a region depending on any state or user action you have to add the into the region by hand. Have a look at the Stock Trader Reference Inplementation. It explains in a very simple manner how to add views to regions triggered by user action.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文