internal void HighlightCorrectButton(Type pageType, object pageParam) { DebugWrite($"PageType: {pageType} PageParam: {pageParam}"); // match type only var buttons = LoadedNavButtons.Where(x => Equals(x.HamburgerButtonInfo.PageType, pageType)); // serialize parameter for matching if (pageParam == null) { pageParam = NavigationService.CurrentPageParam; } else if (pageParam.ToString().StartsWith("{")) { try { pageParam = NavigationService.FrameFacade.SerializationService.Deserialize(pageParam.ToString()); } catch { } } // add parameter match buttons = buttons.Where(x => Equals(x.HamburgerButtonInfo.PageParameter, null) || Equals(x.HamburgerButtonInfo.PageParameter, pageParam)); var button = buttons.Select(x => x.HamburgerButtonInfo).FirstOrDefault(); Selected = button; }
internal void HighlightCorrectButton(Type pageType, object pageParam) { _isHighlightCorrectButtonRunning = true; try { HamburgerButtonInfo newButton = null; // match type only var buttons = LoadedNavButtons.Where(x => Equals(x.HamburgerButtonInfo.PageType, pageType)); if (buttons.Any()) { // serialize parameter for matching if (pageParam == null) { pageParam = NavigationService.CurrentPageParam; } else if (pageParam.ToString().StartsWith("{")) { try { pageParam = Services.NavigationService.Settings .SerializationStrategy.Deserialize(pageParam.ToString()); } catch { // } } // add parameter match buttons = buttons.Where(x => Equals(x.HamburgerButtonInfo.PageParameter, null) || Equals(x.HamburgerButtonInfo.PageParameter, pageParam)); newButton = buttons.OrderByDescending(x => x.HamburgerButtonInfo.PageParameter) .Select(x => x.HamburgerButtonInfo).FirstOrDefault(); } // Update selected button var oldButton = Selected; if (!ReferenceEquals(oldButton, newButton)) { Selected = newButton; if (oldButton?.ButtonType == HamburgerButtonInfo.ButtonTypes.Toggle) { oldButton.IsChecked = false; } if (newButton?.ButtonType == HamburgerButtonInfo.ButtonTypes.Toggle) { newButton.IsChecked = true; } } // Update internal binding values for both buttons oldButton?.UpdateInternalBindingValues(); newButton?.UpdateInternalBindingValues(); } finally { _isHighlightCorrectButtonRunning = false; } }
async Task UpdateSelectedAsync(HamburgerButtonInfo previous, HamburgerButtonInfo value) { DebugWrite($"OldValue: {previous}, NewValue: {value}"); // pls. do not remove this if statement. this is the fix for #410 (click twice) if (previous != null) { IsOpen = (DisplayMode == SplitViewDisplayMode.CompactInline && IsOpen); } // signal previous if (previous != null && previous != value && previous.IsChecked.Value) { previous.IsChecked = false; previous.RaiseUnselected(); // Workaround for visual state of ToggleButton not reset correctly var fwe = LoadedNavButtons.Where(x => x.HamburgerButtonInfo == previous) .Select(x => x.FrameworkElement) .FirstOrDefault() as Control; if (fwe != null) { VisualStateManager.GoToState(fwe, "Normal", true); } } // navigate only when all navigation buttons have been loaded if (AllNavButtonsAreLoaded && value?.PageType != null) { if (await NavigationService.NavigateAsync(value.PageType, value?.PageParameter, value?.NavigationTransitionInfo)) { IsOpen = (DisplayMode == SplitViewDisplayMode.CompactInline && IsOpen); if (value.ClearHistory) { NavigationService.ClearHistory(); } } else if (NavigationService.CurrentPageType == value.PageType && (NavigationService.CurrentPageParam ?? string.Empty) == (value.PageParameter ?? string.Empty)) { if (value.ClearHistory) { NavigationService.ClearHistory(); } } else if (NavigationService.CurrentPageType == value.PageType) { // just check it } else { return; } } // that's it if null if (value == null) { return; } else { value.IsChecked = (value.ButtonType == HamburgerButtonInfo.ButtonTypes.Toggle); if (previous != value) { value.RaiseSelected(); } } }
async Task SetSelectedAsync(HamburgerButtonInfo previous, HamburgerButtonInfo value) { DebugWrite($"OldValue: {previous}, NewValue: {value}"); // pls. do not remove this if statement. this is the fix for #410 (click twice) if (previous != null) { IsOpen = (DisplayMode == SplitViewDisplayMode.CompactInline && IsOpen); } // signal previous if (previous?.IsChecked ?? true && previous != value) { previous?.RaiseUnselected(); } // reset all, except selected var buttons = LoadedNavButtons.Where(x => x.Value != value); buttons.ForEach(x => x.Value.IsChecked = false); // navigate only when all navigation buttons have been loaded if (AllNavButtonsAreLoaded && value?.PageType != null) { if (await NavigationService.NavigateAsync(value.PageType, value?.PageParameter, value?.NavigationTransitionInfo)) { IsOpen = (DisplayMode == SplitViewDisplayMode.CompactInline && IsOpen); if (value.ClearHistory) { NavigationService.ClearHistory(); } } else if (NavigationService.CurrentPageType == value.PageType && (NavigationService.CurrentPageParam ?? string.Empty) == (value.PageParameter ?? string.Empty)) { if (value.ClearHistory) { NavigationService.ClearHistory(); } } else if (NavigationService.CurrentPageType == value.PageType) { // just check it } else { return; } } // that's it if null if (value == null) { return; } else { value.IsChecked = (value.ButtonType == HamburgerButtonInfo.ButtonTypes.Toggle); if (previous != value) { value.RaiseSelected(); } } }