3

I have an aplication with three regions. Region A is a navigation area to hold navigation items for modules in the app. Regions B and C are content areas for the modules. I also have two Modules Module1 and Module2 which each have a Navigation Item Control loaded into Region A. Region A contains NavigationItemMod1Control and NavigationItemMod2Control.

NavigationItemMod1Control is bound to a command which loads view1B into region B and view1C into region C (NavigationItemMod2Control has a similar command). Command execute method shown below:

public void Execute(object parameter)
 {
        // Show View 1B
        var view1BUri = new  Uri(Module1RegionNames.ViewBControl, UriKind.Relative);
        regionManager.RequestNavigate(RegionNames.ViewBArea, view1BUri );

        // Show View 1C
        var view1CUri = new Uri(Module1RegionNames.ViewCControl, UriKind.Relative);
        regionManager.RequestNavigate(RegionNames.ViewCArea, view1CUri );
}

When I click on NavigationItemMod2Control, I want to confirm navigation before loading either view 2B or view 2C into respective regions.

I've successfully implemented IConfirmNavigationRequest on the viewmodel for View1B in Module 1 , but this only controls navigation for region B. If the user cancels the navigation request, region B correctly stays as View1B, but View2C is loaded into region C.

Any suggestions on how to confirm navigation once for both regions?

Tiggy
  • 65
  • 8
  • Why can't you implement the `IConfirmNavigationRequest` for the viewmodel of your `view1C`? – dymanoid Feb 16 '15 at 16:37
  • @dymanoid I had considered this but I'd like to manage the navigation confirmation for all views in Module 1 in a single place – Tiggy Feb 16 '15 at 16:52

1 Answers1

1

The request navigate comes with an overload that supports a callback:

var navigationParameters = new NavigationParameters();
                    navigationParameters.Add("RelatieId", _CurrentRelatie.RelatieId);
regionManager.RequestNavigate("RelatieDetailRegion",
                        new Uri("RelatieDetail", UriKind.Relative), NavigationCallback, navigationParameters);

void NavigationCallback(NavigationResult nr)
    {
        _logger.Log("NavigationCallback", Category.Info, Priority.Medium);
        if (nr.Result.Value == true)
        {

             //navigate region C, so this is your code
             var view1CUri = new Uri(Module1RegionNames.ViewCControl, UriKind.Relative);
             regionManager.RequestNavigate(RegionNames.ViewCArea, view1CUri );
        }
    }

this is based on a code snippet of mine, you'll have to tweak a little, for instance not to use the navigationparameters, which you don't use.

Philip Stuyck
  • 7,344
  • 3
  • 28
  • 39
  • Thanks - this solves my immediate problem.Is there a way to enforce this pattern? Other devs will be adding more modules soon and will need similar logic there. I've thought about creating a base command class that takes the Uri s for ViewB and ViewC in any module and then handles the navigation the way you've suggested. This would work but it relies on everyone using this base class for their commands which is optional at the moment – Tiggy Feb 17 '15 at 10:22