RegionManager architecture pattern question

Apr 14, 2009 at 2:35 PM
I am trying to get used to the concept of modular application.
Perhaps somebody can give me some tips how to handle the following situation:

I have a video module, which displays a list of movies, with three different views.
For this purpose, I thought I take a Movie.class (model), a MovieViewModel.class and a ThumbView, SlimBarView... and so on...
The small views are no problem, but in the details view, I want to be able to add a Toolbar. (e.g. from a rating module)

So, how is the right approach for this, using the regions manager. The movie details view is not visible at the beginning, just a list of 15 movies in thumbnail mode. Who, in this scenario, is responsible for adding the toolbars to each view, when switchting to details mode.

My current train of thought is using an event. DetailsViewEnabledEvent(ViewModelAsArg)
And the "RatingModule" would insert its toolbar in the DetailsView by getting ??a scoped region manager??

Most of the examples deal with "big regions" like 1 Toolbar for the whole application. Which is nice, too, but leaves me a little bit confused for tiny bits, like a list of 100 movies (creating 100 viewModels, using 100 named regions - sounds strange)...

To make it more clear, here is a nice picture to get the idea...
Apr 14, 2009 at 3:45 PM

Hi Christian!

From the detailed scenario you described maybe modularity is not "that" issue.

Here is how may I deal with this situation, since here you've multiple View States but not multiple views, specifically not multiple view models.

In this scenario the view itself can be represented with "just" an ItemsControl and a ViewModel which holds a list of the 100 movies.

It's your choice that are you lazy loading the movie details when a view state is first changed via a service or preload it with other movie data.

It's not clear from you description is that you're showing the different views in the same place or at different part of your application.

You can have a dedicated region within your view for toolbar which can contain anything, but I assume that you can't generalize here, because it's very dependent.

What is the purpose of the toolbar?
1. Show associated data for the given movie? Also provide some interaction (like submit a rating)?
2. Show commands available for that movie? (Rent, Play, etc)
3. Mix of 1 and 2?

For a rating scenario I'd make it part of the initial view model and maybe lazy loading the rating data via a service. This can be encapsulated into a RatingModule, but in this case not the view itself. You can put that into the RatingModule also, but in choose the lifetime for the Rating (or ToolbaR) related stuff wisely to save resources!

So for your scenario I'd use different views but in form of DataTemplates.

Regarding the RegionManager usage I'd have a Toolbar module, which listens to "REGISTER_TOOLBAR_STUFF" event so if any module loaded which like to register something to be shown in the toolbar, it must publish this event along with the attached "metadata" like icommand, displayname and other similar stuff.

The Toolbar module can register it's view into the RegionManager.

What do you think?


Apr 14, 2009 at 4:39 PM
Edited Apr 14, 2009 at 5:27 PM
Thanks for your answer... The more I think about it, there more it takes form.
To stress out, this is not a "real project", so the requirements are very fuzzy.

I want to be able to create the application in multiple steps. The toolbar, for example, is for "anything which might come".
I will try to illustrate the szenario by using versions:

Version 0.1

- Show movies in List (Items Control, with DataTemplate)
- Show details view of Movie (found already some patterns)
- Empty toolbar, cant do anything...

Version 0.2

- No changes

- Big screen for overview of rated movies
- Toolbar inside movie details to rate single movie

Version.... and so on...
I know I might overstretch the modularity a little bit, but I want to hit limitations as early as possible, to figure out what is possible, and what isnt.
In the given szenarion, the movie module would know nothing about the rating module, but the rating would depend on movies. Such things are nicely supported by PRISM.

So what I am basically trying to figure out, is how to "prepare" the movie module for extensions in the future. Perhaps with mockups at the moment, and then later replacing this functionality. And what I am still not quite sure about, is how to "reserve" this region in a good way.

Ok, I think this is a good question:

If I want to reserve a region inside a control for "future use by other modules", do I use a simple named region?
By this "everybody" could add his stuff without needing to know about the others...


Ok, I created a new image to illustrate another question. In this szenario, how would the Toolbar module know when to create the controls for a movie. Would you hook up the "ItemSelectedChangedEvent" to some sort of self created EventRaising(PRISM, e.g.)... I found several models for this "list - details" szenario, but I am not sure how to include the Toolbar in this "non existing views".. (the other 3 movies have potentially also toolbars, but I dont want to load them all if never needed.. Movie-module knows what it shows, so some Event seems to be the best way. Like I said, PleaseShowToolBarForMovieXYZNowEvent... )

By the way, if somebody reads this, take a look at this post, too:

The part about the RegionManager is interesting. I think I will try to "attach my Rating Module" there..
At least I will take a closer look at the region manager. It gets invoked if a details view is opened, so it might be the right place to start..
Apr 15, 2009 at 8:06 PM

Hi Chris,


                Are you using Prism-v1 or Prism-v2? Are you using WPF or Silverlight? I'll assume you are using WPF and Prism-v2.


I agree with Attila that for the scenario you described in your first post, the best way to show a model item (view) with different styles is using DataTemplates and maybe switching templates dynamically using triggers. You might find these MSDN articles interesting:

·         Data Templating Overview.

·         Styling and Templating


Regarding the toolbar, I think the best way would be to define a new scoped region for each model element (Movies in your scenario). You can check how to do this in the How to: Show a View in a Scoped Region development activity from the documentation.
That will solve the part of your question: "If I want to reserve a region inside a control for "future use by other modules", do I use a simple named region?". But the second part: "By this "everybody" could add his stuff without needing to know about the others..." is not that straight forward because you need 2 things:

1.       Get the Toolbar module to know when to create the controls for a movie

2.       Get the toolbar to know on which scoped region to add the controls.


For item 1, the best way is to use the EventAggegator. This way your MovieModule and RatingModule can communicate using events in a decoupled way.  Your MovieModule will create events and publish them when  necessary (each time a movie is selected, changed, etc).The RatingModules subscribe to these events to receive a notification. For more detail on how to do this, you can check How to: Create and Publish Events and How to: Subscribe and Unsubscribe to Events.


For item 2, I think the best way to keep modules decoupled is to pass the corresponding instance of the scoped RegionManager through the event Payload. This is also explained in the How to: Create and Publish Events topic in the Prism-v2 documentation. You will have to create a class similar to the following in a separate project:

public class MovieSelectedEvent : CompositePresentationEvent<IRegionManager>




You can find an example of the EventAggregator being used this way in the Event Aggregation QuickStart.


Hope this helps you find the best way to implement your solution! If you have any further questions or if I was not clear enough, please post again.


Matias Bonaventura