开发者

Prism modularity reload mechanism

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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜