Pawan
Pawan

Reputation: 293

MEF/PRISM Silverlight

I am new to MEF/Prism and Silverlight and I am not sure how to dynamically load modules into a ItemsControl. I basically want to be able to swap out dynamically loaded modules into the same region container. How can I do this using MEF/PRISM?

Upvotes: 2

Views: 926

Answers (2)

PVitt
PVitt

Reputation: 11760

A region to host several controls must be of type ItemsControl:

<ItemsControl 
    x:Name="MainToolbar" 
    cal:RegionManager.RegionName="{x:Static inf:RegionNames.MainToolBarRegion}">
</ItemsControl>

Views can be added and removed by code:

//add view if not already present
IRegion region = this._regionManager.Regions["RegionName"];

object view = region.GetView( "ViewName" );
if ( view == null )
{
    var view = _container.ResolveSessionRelatedView<IMyView>( );
    region.Add( view, "ViewName");
}

//remove
IRegion region = this._regionManager.Regions["RegionName"];

object view = region.GetView( "ViewName" );
if ( view != null )
{
    region.Remove( view );
}

Using this code you could also add the views by code besides using the Prism built-in navigation functionality.

Upvotes: 2

surfen
surfen

Reputation: 4692

The QuickStart project in Prism does exacly what you ask for. It's called Modularity QuickStart :)

Also, have a look at this thread: Using Prism for navigation in Wpf application

View Injection QuickStart does set a view on change of ListView selected item so might be of some help too.

Upvotes: 3

Related Questions