Repository: dotnet/maui
File: src/Core/src/Platform/Windows/MauiNavigationView.cs (C#)

Code before:
				// This changes the menu items grid so it just sizes to its content
				// By default it was always filling the entire container but we don't want that
				ItemsContainerRow.Height = new WGridLength(1, UI.Xaml.GridUnitType.Auto);

				// this forces the custom content to take up the entire height that it can
				PaneContentGrid.RowDefinitions[4].Height = new WGridLength(1, UI.Xaml.GridUnitType.Star);
			}
		}

		private protected virtual void OnApplyTemplateCore()
		{
		}

		internal void UpdatePaneDisplayModeFromFlyoutBehavior(FlyoutBehavior flyoutBehavior)
		{
			if (_currentFlyoutBehavior == (int)flyoutBehavior)
			{
				return;
			}

			_currentFlyoutBehavior = (int)flyoutBehavior;
			switch (flyoutBehavior)
			{
				case FlyoutBehavior.Flyout:
					IsPaneToggleButtonVisible = true;
					// Updating the same PaneDisplayMode at the runtime causes selection related issues
					// the selected item not updating correctly. So only set it when it's different.
					if (PaneDisplayMode != NavigationViewPaneDisplayMode.LeftMinimal)
					{
						PaneDisplayMode = NavigationViewPaneDisplayMode.LeftMinimal;
					}
					break;
				case FlyoutBehavior.Locked:
					PaneDisplayMode = NavigationViewPaneDisplayMode.Left;
					IsPaneToggleButtonVisible = false;
					break;
				case FlyoutBehavior.Disabled:
					PaneDisplayMode = NavigationViewPaneDisplayMode.LeftMinimal;
					IsPaneToggleButtonVisible = false;
					IsPaneOpen = false;
					break;
			}
		}

		#region Toolbar
		internal static readonly DependencyProperty ToolbarProperty
			= DependencyProperty.Register(nameof(Toolbar), typeof(UIElement), typeof(MauiNavigationView),
				new PropertyMetadata(null, (d, _) => ((RootNavigationView)d).ToolbarChanged()));

		internal UIElement? Toolbar
		{

Review comment (bug):
Could expand the comment to include more details, like the link to the original issue?

```
// WinUI bug: Setting PaneDisplayMode to the same value during navigation
// causes the selected item indicator to not update correctly.
// Workaround: Only set PaneDisplayMode when the value actually changes.
// Related: https://github.com/microsoft/microsoft-ui-xaml/issues/9812
```

Code after:
				// This changes the menu items grid so it just sizes to its content
				// By default it was always filling the entire container but we don't want that
				ItemsContainerRow.Height = new WGridLength(1, UI.Xaml.GridUnitType.Auto);

				// this forces the custom content to take up the entire height that it can
				PaneContentGrid.RowDefinitions[4].Height = new WGridLength(1, UI.Xaml.GridUnitType.Star);
			}
		}

		private protected virtual void OnApplyTemplateCore()
		{
		}

		internal void UpdatePaneDisplayModeFromFlyoutBehavior(FlyoutBehavior flyoutBehavior)
		{
			if (_currentFlyoutBehavior == (int)flyoutBehavior)
			{
				return;
			}

			_currentFlyoutBehavior = (int)flyoutBehavior;
			switch (flyoutBehavior)
			{
				case FlyoutBehavior.Flyout:
					IsPaneToggleButtonVisible = true;
					// WinUI bug: Setting PaneDisplayMode to the same value and updating SelectedItem during navigation
					// causes the selection and selected item indicator to not update correctly.
					// Workaround: Only set PaneDisplayMode when the value actually changes.
					// Related: https://github.com/microsoft/microsoft-ui-xaml/issues/9812
					if (PaneDisplayMode != NavigationViewPaneDisplayMode.LeftMinimal)
					{
						PaneDisplayMode = NavigationViewPaneDisplayMode.LeftMinimal;
					}
					break;
				case FlyoutBehavior.Locked:
					PaneDisplayMode = NavigationViewPaneDisplayMode.Left;
					IsPaneToggleButtonVisible = false;
					break;
				case FlyoutBehavior.Disabled:
					PaneDisplayMode = NavigationViewPaneDisplayMode.LeftMinimal;
					IsPaneToggleButtonVisible = false;
					IsPaneOpen = false;
					break;
			}
		}

		#region Toolbar
		internal static readonly DependencyProperty ToolbarProperty
			= DependencyProperty.Register(nameof(Toolbar), typeof(UIElement), typeof(MauiNavigationView),
				new PropertyMetadata(null, (d, _) => ((RootNavigationView)d).ToolbarChanged()));