WPF wizard Page in PRISM Desktop application

Topics: Prism v4 - WPF 4
Feb 12, 2013 at 9:27 PM
I am using Unity with Prism 4.1 and working on to create wizard page for add an employee to the database. The new employee form has 2 Views.

1st view (NewEmployeePage1) gathers name and address and some other additional details with next and cancel buttons, 2nd view (NewEmployeePage2) gathers preferences and few other information with back, cancel and finish buttons.

When I navigate to the NewEmployeePage1, I would like to the page to be in New Mode every time the new button is pressed (New Button is on the top level application menu). This does not happen if I dont set the RegionMemberLifeTime to false. But this causes the data to be cleared whent he user clicks back from the previous page.

When the user fills the data and presses next it moves to the second page (Not sure how I do the view injection for this). How do I navigate to the next view (NewEmployeePage2)? I use the delegatecommand but using RequestNavigate gives System.Object and does not show the next page. I am thinking the view is not registered? But I dont want to carry the UnityContainer on to the view models register. May be I am missing some thing.

Any advise on how I should do the view injection to clear data only when the New Employee page is clicked for the first time.
Developer
Feb 13, 2013 at 8:11 PM
Hi,

Based on the description of your scenario, I believe that using Region Navigation could be a useful approach.

First of all, in order to being able to navigate to your NewEmployeePage1 and NewEmployeePage2 views you will need to register them for navigation in the Unity container. You can register them in the module by doing something like this:
public WizardModule(IUnityContainer container)
{
    this.container = container;
}

public void Initialize()
{
    this.container.RegisterType<object, NewEmployeePage1>("NewEmployeePage1");
    this.container.RegisterType<object, NewEmployeePage2>("NewEmployeePage2");
}
After that you should be able to use a navigation request to navigate to those views. Like this, you should be able to navigate to the NewEmployeePage1 from any command and also navigate to the NewEmployeePage2 view from the "Next" command without needing the views to know each other (as you use the view's names instead of the type.) Also, you can navigate back from the NewEmployeePage2 view to the NewEmployeePage1 view using the NavigationJournal (or a common navigation request.)

Finally, to solve the problem about regarding the NewEmployeePage1 view, I believe a possible approach could be to use the IRegionMemberLifetime interface, the INavigationAware interface and the a parameter in the navigation request. By default, the view model of the NewEmployeePage1 could return true in both its KeepAlive property and its IsNavigationTarget method. Like this, the view will be kept alive and you can navigate back and forth from the NewEmployeePage2. Then, when you need to inject a clear NewEmployeePage1 view, you could use a navigation request with a parameter such as "new=true". You can check for this parameter in the IsNavigationTarget method and if it's present you could set the KeepAlive property to false and return false in the aforementioned method. Like this, a new view will be created an the previous one will be removed from the region.

You can find more information about navigation in the following chapter of the Prism documentation:
I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini
Feb 14, 2013 at 2:15 PM
Edited Feb 14, 2013 at 2:17 PM
Hello Damian

Thanks for your comments. It worked perfectly for the first comment. I was missing the piece of registering in the module Initialization. I was also under the impression that registering actually resolves it. But in fact it resolves only when it is activated or navigated to.

I now have to figure the KeepAlive as you suggested and tweak to the business needs. I am sure it will work like you mentioned. I did a quick check and it was good. But the Finish button and deciding if to use single view model for both pages is what I am deciding. If I have to have single view model for both pages, I have to think of passing the context of page 1 to page 2.

I really appreciate your time!