Multiple Region Instances

Jul 3, 2008 at 12:54 PM
The project I am working on is going to have more than one of a particular module view.  These views have a region within them.  Is it possible to dynamically name a region. 

For example:

I am planning on having a tab control that will contain a tab for each client.  In each tab, I am expecting to have an outer region which I will be dynamically adding views.  The problem is that the only way I know how to name a region is to declare it in WPF.   What I am going to end up with is regions as follows

MainAreaRegion
    TabAreaRegion
        Tab1
            OuterRegion
                ClientHistoryView
        Tab2
            OuterRegion
                ClientHistoryView

The problem is that I am not sure how to reference The first OuterRegion or the second OuterRegion.  I am also assuming that this would crash due to identicial items.
Any help or suggestion would be greatly appreciated.

Ben
Jul 3, 2008 at 2:25 PM
It appears that in the UIComposition quick start they are doing something like this in the EmployeesDetailView.xaml and the EmployeesController.cs files.

They are using nested RegionManagers for what would be your individual tabs.

Take a look and see if it can be adapted to your needs.

Paul
Jul 4, 2008 at 1:36 AM
Paul, thank you for your response, but no this isn't the same...Each tab is a unique region.   I my example, each tab is the client so each tab would have the same regions and views on them.

I will expand my sample

MainAreaRegion
    TabAreaRegion
        Tab1 Client Blow, Joe
            OuterRegion
                ClientHistoryView
        Tab2 Client Doe, Jane
            OuterRegion
                ClientHistoryView

As shown above, each tab will be a client that they chose to open and work on.  (similar to visual studios)  I would like to then have a dynamic area that custom modules will be shown.  This is where my problem is.  Since the client history area won't change much between clients, the regions would be identical.  I don't know how many clients they will have open at a time.  In the future, I would like them to even be able to compare the items on the tabs.(sort of like splitting the visual studio horizontally and vertically ). 

Ben
Jul 4, 2008 at 2:58 AM
Would this be similar to the SCSF Quickstarts.BankTeller sample? If so, I've done this but by using my DocumentManager approach. I'll be adding it to the LateNight sample here soon, take a look at this and apply the following strategy.

Create an interface to your view that exposes a document controller for each tabbed area you wish to expose.

    public interface ICustomerViewModel {
        IDocumentController CustomerViewExtensionController { get; }
        Customer Customer { get; }
    }

Now inherit this in your models definition:

    public class CustomerViewModel : AbstractDocument, ICustomerViewModel { //... }

Represent the model from the UI

    <TabControl MinHeight="100"
                ItemsSource="{Binding CustomerViewExtensionController.Documents}"
                SelectedItem="{Binding Path=CustomerViewExtensionController.CurrentDocument}">
        <!-- Item and control templates. -->
    </TabControl>

Since the document controller exposes events for documents being opened/closed, add a handler to the DocumentOpening event for the main document controller.

    var documentController = container.Resolve<IDocumentController>(
        ControllerNames.DocumentController);
    documentController.DocumentOpened
        += new EventHandler<DataEventArgs<AbstractDocument>>(DoDocumentOpened);

With a handler like the following:

    private void DoDocumentOpened(object sender, DataEventArgs<AbstractDocument> e) {
        ICustomerViewModel cm = e.Value as ICustomerViewModel;
        if (cm != null) {
            cm.CustomerViewExtensionController.OpenDocument(new CustomerCommentsViewModel(cm));
        }
    }

And that's basically it. I know it doesn't use any RegionManager and I probably should, but I felt this the easiest way of solving the problem. I hope to have a full example ready in the subversion source of my project in the next few days.

-Brett
Jul 4, 2008 at 1:35 PM


planefun wrote:
Paul, thank you for your response, but no this isn't the same...Each tab is a unique region.   I my example, each tab is the client so each tab would have the same regions and views on them.

I will expand my sample

MainAreaRegion
    TabAreaRegion
        Tab1 Client Blow, Joe
            OuterRegion
                ClientHistoryView
        Tab2 Client Doe, Jane
            OuterRegion
                ClientHistoryView

As shown above, each tab will be a client that they chose to open and work on.  (similar to visual studios)  I would like to then have a dynamic area that custom modules will be shown.  This is where my problem is.  Since the client history area won't change much between clients, the regions would be identical.  I don't know how many clients they will have open at a time.  In the future, I would like them to even be able to compare the items on the tabs.(sort of like splitting the visual studio horizontally and vertically ). 

Ben



I understand, I was referring to the nested regions in the code.  They are creating a new reginon manager.and registering the view in that.  If you register each like named region into a different region manager I wouldnt think that there would any name collisions.

Paul