2

Closed

NavigationService.GoBack does not update CurrentPageKey (Universal App)

description

If I call MVVM Light's NavigationService.GoBack(), the app correctly goes back to the previous page on the stack.

However, the NavigationService.GoBack() implementation for Universal Apps (Win 8.1 / WP 8.1) does not update the CurrentPageKey to reflect that we're back at the previous page / ViewModel.

With no way to override the CurrentPageKey (private setter), the value is therefore wrong once you call GoBack(). Only alternative would be to always use NavigateTo() instead of GoBack() when returning to the previous page. But that would completely mess up the navigation stack.

NavigationService class



Plus, it would be important to know from GoBack() if there actually was a previous page on the navigation stack. If no previous page is on the navigation stack, the app usually has to close. When taking the back hardware button into account on WP 8.1, I need to know whether I should set the event to "handled" or not - i.e., if the NavigationService successfully went back to the previous page or not.

So, the GoBack() method should return a bool if it was possible to go back or not. Ideally, it should also expose a method like "bool CanGoBack()" to check beforehand. It's handled like that in the NavigationHelper.cs that is part of the Universal App template by Microsoft.
Closed Feb 15, 2015 at 5:13 PM by lbugnion

comments

lbugnion wrote Oct 18, 2014 at 6:36 PM

Like Homer would say DOH about the CurrentPageKey. You are absolutely right of course, will fix ASAP.

Good feedback about the CanGoBack. The challenge of course is to implement it in a consistent manner on all platforms. I will try.

Thanks!
Laurent

lbugnion wrote Feb 6, 2015 at 2:28 PM

Fixed in V5.1 (upcoming)

lbugnion wrote Feb 6, 2015 at 4:12 PM

DLLs are available here:
http://1drv.ms/1ylP1TS

Nuget will be updated ASAP.