Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ void UnhookEventsAndClearFields(bool isFromDestructor = false)
static NavigationView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NavigationView), new FrameworkPropertyMetadata(typeof(NavigationView)));
EventManager.RegisterClassHandler(typeof(NavigationView), KeyDownEvent, new KeyEventHandler(OnHandleKeyDown), true);
}

static void OnHandleKeyDown(object sender, KeyEventArgs args)
{
//ScrollViewer && TextBox of AutoSuggestBox set Handled to true, so it doesn't bubble to KeyboardFocusManager.
if (sender is not NavigationView navView)
{
return;
}

if (navView.NoNeedToBubbleKeyEvents)
{
navView.NoNeedToBubbleKeyEvents = false;
return;
}

args.Handled = false;
}

public NavigationView()
Expand Down Expand Up @@ -2863,6 +2881,8 @@ void OnNavigationViewItemKeyDown(object sender, KeyEventArgs args)
}
}

private bool NoNeedToBubbleKeyEvents { get; set; }

void HandleKeyEventForNavigationViewItem(NavigationViewItem nvi, KeyEventArgs args)
{
var key = args.Key;
Expand All @@ -2871,14 +2891,17 @@ void HandleKeyEventForNavigationViewItem(NavigationViewItem nvi, KeyEventArgs ar
case Key.Enter:
case Key.Space:
args.Handled = true;
NoNeedToBubbleKeyEvents = true;
OnNavigationViewItemInvoked(nvi);
break;
case Key.Home:
args.Handled = true;
NoNeedToBubbleKeyEvents = true;
KeyboardFocusFirstItemFromItem(nvi);
break;
case Key.End:
args.Handled = true;
NoNeedToBubbleKeyEvents = true;
KeyboardFocusLastItemFromItem(nvi);
break;
case Key.Down:
Expand Down Expand Up @@ -2927,12 +2950,16 @@ void FocusNextUpItem(NavigationViewItem nvi, KeyEventArgs args)
if (childRepeater.MoveFocus(new TraversalRequest(FocusNavigationDirection.Last)))
{
args.Handled = true;
NoNeedToBubbleKeyEvents = true;
}
else
{
args.Handled = nextFocusableNVIImpl.Focus(/*FocusState.Keyboard*/);
args.Handled = nextFocusableNVIImpl.Focus( /*FocusState.Keyboard*/);
if (args.Handled)
{
NoNeedToBubbleKeyEvents = true;
}
}

}
}
else
Expand All @@ -2948,7 +2975,11 @@ void FocusNextUpItem(NavigationViewItem nvi, KeyEventArgs args)
{
if (GetParentNavigationViewItemForContainer(nvi) is { } parentContainer)
{
args.Handled = parentContainer.Focus(/*FocusState.Keyboard*/);
args.Handled = parentContainer.Focus( /*FocusState.Keyboard*/);
if (args.Handled)
{
NoNeedToBubbleKeyEvents = true;
}
}
}
}
Expand All @@ -2972,14 +3003,12 @@ void FocusNextDownItem(NavigationViewItem nvi, KeyEventArgs args)
// args.Handled = controlFirst.Focus(/*FocusState.Keyboard*/);
//}
args.Handled = childRepeater.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
if (args.Handled)
{
NoNeedToBubbleKeyEvents = true;
}
}
}

// WPF
if (!args.Handled)
{
args.Handled = nvi.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
}
}

// WPF
Expand Down
Loading