WPF Prism navigation - previous and next view RRS feed

  • Question

  • I'm developing a wpf application using prism and MVVM.

    I have a main shell, which has two regions: Menu region and Main region.

    I'm trying to implement within the menu region (which contains the MenuView) a BACK and FORWARD buttons, exactly as we have in any browser: Let's say I have 5 views: View1, View2, View3, View4, View5. When I launch the application, View1 is shown in the Main Region. For the current moment, I want those buttons to be disabled. Now, I choose to navigate to View3: View3 is shown in the Main Region, and then the Back btn becomes enabled (the forward btn is remained disabled). Then, I navigate to View2, and it is displayed in Main Region.

    Now, when I click Back btn, View 3 is displayed in Main Region, and the Forward btn becomes enabled. I click Forward, and Now View 2 is displayed, and Forward btn becomes disabled.

    I've tried using the Navigation Journal, as explained in the following link: http://msdn.microsoft.com/en-us/library/gg430861(v=pandp.40).aspx

    But had no success, because I did what they mentioned in the MenuViewModel, which is the only view that is dispayed in the Menu region for the whole application life (and only Main Region switches views). That's why, OnNavigatedTo method is never called, cause I never nevigate to the MenuView, and this causes navigationService to always be null.

    The main point is that I want these buttons in the MenuView - the only view displayed in the Menu Region for all the application life. And the Back and forward buttons navigate between views in the Main Region - back and forth. Would appreaciate your suggestions.

    Saturday, September 20, 2014 12:40 PM


  • This is how I solved it:

    From the MenuViewModel, I have a reference to the regionmanager, so I can get access to the main region and it's navigation service:

    var mainregion = _regionManager.Regions[RegionNames.mainregion];
    • Marked as answer by DK1987 Friday, September 26, 2014 11:57 AM
    Friday, September 26, 2014 11:57 AM

All replies