Creating a Navigator

Topics: Prism v4 - WPF 4
Aug 19, 2010 at 12:57 PM
Edited Aug 19, 2010 at 1:10 PM

Just started working on Prism recently. I really like what I see but am finding some simple things to be difficult, among them this...

I started a Prism project, the first thing in the 1st project was the Shell and Bootstrapper. Was able to get it up and running with Views etc. So now I want to modularize by putting each new module in it's own project. Not a problem, was able to do that and to get the Bootstrapper to add to catalog and the "other projects" to load up in shell.

My problem is this, how do I create a navigator project which knows about all the other projects and can push Views into shell?

In the CompositeUI samples there is a push example, I've learned from that, that the Navigator Project (Module) must have a way to accept the IUnityContainer as well as the IRegion manager in the default IModule for the Navigator project. Here's the flow:

Prism Flow for Navigator Project


BootStrapper places the Navigator in moduleCatalog...


Naviation IModule

The Navigation Module CTOR is this...

public NavigationModule(IUnityContainer container, IRegionManager regionManager)

The Navigation Module Initilize looks like this.... the Naviation module is taking responsibility for loading default Body content and default Navigation content.. The Navigation content is just a set of buttons in a stack panel on right hand side of Shell.

      public void Initialize()        {

            OtherProject.Views.ViewA sc = this.container.Resolve<OtherProject.Views.ViewA >();
            IRegion mainRegion = this.regionManager.Regions["Body"];
            Views.MainNavigation nav = this.container.Resolve<Views.MainNavigation>();
            IRegion navigator = this.regionManager.Regions["Navigation"];

        protected void RegisterViewsAndServices()
            this.container.RegisterType<OtherProject.Views.ViewA >();

The above code works fine as the first two default views are loaded into Shell.

The Navigator View

The Navigator View handles the button click which should change the view to any of the other projects I have in this solution. So in the Button Click events of that view, I started working on code like this:

Step 1) Definitely not best practice, but I had to get reference to the MainRegion which I stored as static variable in the IModule of the Navigator...

IRegion mainRegion = NavigationModule._regionManager.Regions["Body"];

Step 2) Get the ViewCollection of Main Region IViewsCollection vc = mainRegion.ActiveViews;

Step 3) Iterate the View collection looking for Views, activate the one you want.

foreach (var thing in vc)
                if (thing.GetType().Name == "QualityAssuranceView")
                    QAModule.Views.QualityAssuranceView qamod = thing as QAModule.Views.QualityAssuranceView;
                    found = true;
                else {
                    //need to new up an instance of view?  Not sure how to do this the Prism way... Remember this Navigator View is just an injected view in the Shell...                

So my problem is this: 1) I was able to iterate the view collection and find what I expected, in example above I do fing the QAModule and cast it and activate it. But what I found is that when I do this same thing for another view, the Activate seems to work but I don't see the new module in the Shell...

Seems like a simple thing to do "Change Views using a Navigator within Prism Architecture using mulitple Project Views", but It's still a mystery to me... Any guidance would be appreaciated.

Sep 13, 2010 at 5:46 PM

We are working on guidance on different types of navigation.  Rather than answer your questions directly, I'm going to point you at one of the quickstarts that is in Drop 7.  It is currently called the RegionNaviagion Quickstart in the Navigation folder under Quickstarts.  This Quickstart uses a different approach than the one you have outlined, where modules register a view in a navigation pane and use a navigation service to hook things up.

There are currently no docs for this as they are still being written, but the code may help you out.