In Prism, you usually make a tab control a scope so that you don't have to control the collection of tab-bound tabs.
<TabControl x:Name="MainRegionHost" Regions:RegionManager.RegionName="MainRegion" />
Now you can add views by registering in the MainRegion region:
RegionManager.RegisterViewWithRegion( "MainRegion", ( ) => Container.Resolve<IMyViewModel>( ).View );
And here you can see the specialty of Prism. A view is created using the ViewModel. In my case, I enable ViewModel through the Inversion of Control container (e.g. Unity or MEF). The ViewModel receives the view introduced through the constructor installation and sets itself as the context for the data view.
An alternative is to register the type of the view in the region controller:
RegionManager.RegisterViewWithRegion( "MainRegion", typeof( MyView ) );
Using this approach, you can create views later at runtime, for example. using the controller:
IRegion region = this._regionManager.Regions["MainRegion"]; object mainView = region.GetView( MainViewName ); if ( mainView == null ) { var view = _container.ResolveSessionRelatedView<MainView>( ); region.Add( view, MainViewName ); }
Since you registered the view type, the view is placed in the correct area.
PVitt Apr 14 '11 at 7:00 2011-04-14 07:00
source share