/// <summary> /// Ensures the nav menu reflects reality when navigation is triggered outside of /// the nav menu buttons. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnNavigatingToPage(object sender, NavigatingCancelEventArgs e) { var snooStreamViewModel = Application.Current.Resources["SnooStream"] as SnooStreamViewModel; if (SnooStreamViewModel.NavigationService == null) { var navService = new NavigationService(AppFrame, snooStreamViewModel); SnooStreamViewModel.NavigationService = navService; navService.Finish(snooStreamViewModel.GetNavigationBlob()); } var navVM = ((SnooStreamViewModel)App.Current.Resources["SnooStream"]).NavMenu; if (e.NavigationMode == NavigationMode.Back) { var item = (from p in navVM.Items where MapVMToPageType(p.VM) == e.SourcePageType select p).SingleOrDefault(); if (item == null && this.AppFrame.BackStackDepth > 0) { // In cases where a page drills into sub-pages then we'll highlight the most recent // navigation menu item that appears in the BackStack foreach (var entry in this.AppFrame.BackStack.Reverse()) { item = (from p in navVM.Items where MapVMToPageType(p.VM) == entry.SourcePageType select p).SingleOrDefault(); if (item != null) break; } } var container = (ListViewItem)NavMenuList.ContainerFromItem(item); // While updating the selection state of the item prevent it from taking keyboard focus. If a // user is invoking the back button via the keyboard causing the selected nav menu item to change // then focus will remain on the back button. if (container != null) container.IsTabStop = false; NavMenuList.SetSelectedItem(container); if (container != null) container.IsTabStop = true; } }