Scoped RegionManagers with Multi-View Modules

Dec 7, 2008 at 12:43 PM

We are creating a set of implementation pattern examples fora future WPF application using Prism and many of the patterns

Conceptually, we will have a single shell rolled out to theusers.  As new functionality is added tothe application, we will roll out new modules.

WPF is quite new to our developers.   I have been working on a pattern in areference implementation that uses MVP but I am running into some difficultieswhen I need to have two different views present in the same module.

I have created 3 views instead of 2:  a “HOST” view that has two content areas, aList View and a Details View.  The moduleinitialization registers all of the views and their presenters and the sharedservice as well as a controller.  TheHOST view and presenter are “stupid”; their only purpose is to host the detailsand list views.  The controller handlescommunication between the list and detail presenters/views.

Here is the module’s structure:

TeamTracker.Modules.TeamMember<o:p></o:p>

       Controllers<o:p></o:p>

              ITeamMemberController.cs<o:p></o:p>

TeamMemberController.cs<o:p></o:p>

       Models<o:p></o:p>

              ITeamMemberDetailsCompositeModel.cs<o:p></o:p>

TeamMemberDetailsCompositeModel.cs<o:p></o:p>

       Services<o:p></o:p>

              ITeamMemberService.cs<o:p></o:p>

              TeamMemberService.cs<o:p></o:p>

       Views<o:p></o:p>

              TeamMemberDetails<o:p></o:p>

ITeamMemberDetailsPresenter.cs<o:p></o:p>

ITeamMemberDetailsView.cs<o:p></o:p>

TeamMemberDetailsPresenter.cs<o:p></o:p>

TeamMemberDetailsView.XAML/ xaml.cs<o:p></o:p>

TeamMemberHost<o:p></o:p>

ITeamMemberHostPresenter.cs<o:p></o:p>

ITeamMemberHostView.cs<o:p></o:p>

TeamMemberHostPresenter.cs<o:p></o:p>

TeamMemberHostView.XAML/ xaml.cs<o:p></o:p>

TeamMemberList<o:p></o:p>

ITeamMemberListPresenter.cs<o:p></o:p>

ITeamMemberListView.cs<o:p></o:p>

TeamMemberListPresenter.cs<o:p></o:p>

TeamMemberLostView.XAML/ xaml.cs<o:p></o:p>

<o:p> </o:p>

My question is about how declare and use regions within the HostView.XAMLand the use of a scopedRegionManager.

Initially, I declared two content areas

<ContentControl x:Name="TeamMemberListRegion"Grid.Column="0" VerticalAlignment="Top"/>-<ContentControlx:Name="TeamMemberDetailsRegion" Grid.Column="1" /><o:p></o:p>

This is the HOSTPresenter constructor:

       public TeamMemberHostPresenter(<o:p></o:p>

                    ITeamMemberControllerteamController,<o:p></o:p>

                    ITeamMemberHostView view,<o:p></o:p>

                    ITeamMemberListPresenterlistPresenter,<o:p></o:p>

                    ITeamMemberDetailsPresenterdetailsPresenter)<o:p></o:p>

<o:p> </o:p>

        {<o:p></o:p>

<o:p> </o:p>

            _view = view;<o:p></o:p>

            _listPresenter = listPresenter;<o:p></o:p>

            _detailsPresenter =detailsPresenter;<o:p></o:p>

            <o:p></o:p>

            _teamController = teamController;<o:p></o:p>

           _view.LoadTeamListView(_listPresenter.View);<o:p></o:p>

           _view.LoadTeamDetailsView(_detailsPresenter.View);             <o:p></o:p>

         }

<o:p> </o:p>

<o:p> </o:p>

_view.LoadTeamListViewhas one job:   TeamMemberListRegion.Content= teamMemberListView<o:p></o:p>

_view.LoadTeamDetailshas one job:    TeamMemberDetailsRegion.Content= teamMemberDetailsView<o:p></o:p>

<o:p> </o:p>

This worked…….at first…..

<o:p> </o:p>

<o:p> </o:p>

As I iteratethough adding more functionality such as the use of a composite model (multiplebusiness entities) for the teamMemberDetailsView and validation architectureusing Martin Bennedik’s

WPF integrationfor VAB, I am starting to see failures where the teamMemberDetailsViewdoes not properly update to show new data.

<o:p> </o:p>

I amwondering if this has to do with the use of the ContentControl instead ofItemsControl.

 

Is itpossible to declare regions using ItemsControl in my HOSTView.XAML?  I was unsure if it is possible to have nestedregion managers? I was looking at using scoped region managers (from thePrism.chm):

IRegiondetailsRegion = this.regionManager.Regions["DetailsRegion"];<o:p></o:p>

Viewview = new View();<o:p></o:p>

boolcreateRegionManagerScope = true;<o:p></o:p>

IRegionManagerdetailsRegionManager = detailsRegion.Add(view, null,createRegionManagerScope);<o:p></o:p>

<o:p>  </o:p>

Assuming theregions in the HOST.XAML are called TeamMemberDetailsRegion and TeamMemberListRegion, how do I create the scoped region manager for use by the HOSTPresenter?  The SHELL.XAML region is where the TeamMember Module is loaded is called  "TeamListRegion".

<o:p></o:p>

How do I create the ScopedRegionManager using the regions I've explained?

<o:p> (On a side note, the UIComposition.sln shows an example inModules \ Controllers \ EmployeesController.cs  OnEmployeeSelected() method.  This,however, is creating a new view for each employee??  I want to have a single view and update thesingle View.Model since the screen has edit capabilities instead of being viewonly.) </o:p>