Looking for Code Example: Tabbed scoped regions

Topics: Prism v4 - WPF 4
Oct 7, 2011 at 11:47 PM
Edited Oct 7, 2011 at 11:50 PM

I've been looking everywhere for a full and complete code example that demonstrates using scoped regions and tabs.  All I can find are snippets of code which simply isn't helping me get the entire picture.

* Prism/WPF 4, MVVM, Event Aggregator

(the short story)

In short I'm trying to get a single view to show up on multiple tabs, think a single customer record on each tab.  Plus I want to show other types of views on tabs, not just customers.

(the longer story)

The scenario I'm trying to sort out is:

I have a shell with a tabbed control, region name = Workspace.

I load a HomePage module that injects a view into Workspace and has a nested ItemControl region for HomePageItems - No problem.

I load a Customer module with MEF that has a HomePageItemView that I inject into the HomePageItems region - No problem.

That view has a button which when clicked, raises an event subscribed to by my event service - No problem.

That event service gets the event, generates a GUID (my session key) and raises another event with that session key as the payload - No problem.

My Customer module has a controller class that subscribes to and gets the event.  Then it injects a new instance of the CustomerWorkspace view into the Shell's Workspace region, this shows up as a new tab as it should - No problem.

In the UI, I click back to the HomePage tab, click the Customer.HomePageItemView button again, events are handled properly and my Customer controller gets the event asking it to create another customer workspace (this is what I want, a new tab everytime I load a new customer view).  This is where it doesn't work.

At that point I get the expected "View already exists" error which I understand.  I inject the prism RegionManager into the Customer module and know I can't add a view with the same name to the RegionManager twice.

My probelm is in trying to figure out where to use scoped regions.

A working code example (not just the 5 lines on how to overload the Region.Add() method to return a new regionmanager) would really help.

I tried reviewing the Stock TRader RI but that both uses Unity and is way overkill with indirection that I don't care to figure out at this time.  Plus, I don't see any use of scoped regions there nor does it use tabs.

Anyways, at this point I'm hoping to find some good sample projects if anyone knows of anything.

Otherwise I'll keep posting more detail about this since I simply can't seem to get it working.

Cheers

Oct 8, 2011 at 5:58 PM

Big sigh...

Looks like my only problem was not having the NonShared attribute on my view.

[PartCreationPolicy(System.ComponentModel.Composition.CreationPolicy.NonShared)]

The worst part was the error and my research into all led me down the road of scoped regions.  That had nothing to do with my actual problem which is why I couldn't find anything that worked.

I still wasn't able to find any good code examples that dealt specifically with what I was looking for.

Cheers

 



Developer
Oct 11, 2011 at 9:59 PM

Hi,

I’m glad that you’ve found a solution to your original problem; thank you for sharing it with the rest of the community.

Regarding the sample with a tabbed control, you might find the UI Composition QuickStart of the Prism library useful. This QuickStart contains a view named EmployeeSummaryView which has a TabControl and is injected in the shell. The aforementioned TabControl is also registered as a region where the EmployeeDetailsView view and the EmployeeProjectsView view are later injected.

I hope you find it useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini