Skip to content

Conversation

@AndrewKeepCoding
Copy link
Contributor

Fixes #745

You can navigate to Segmented2 with the right key, but can't navigate back to Segmented1 with the left key.

<StackPanel Orientation="Horizontal" XYFocusKeyboardNavigation="Enabled">

    <toolkit:Segmented x:Name="Segmented1">
        <toolkit:SegmentedItem Content="Item 1" />
        <toolkit:SegmentedItem Content="Item 2" />
        <toolkit:SegmentedItem Content="Item 3" />
    </toolkit:Segmented>

    <toolkit:Segmented x:Name="Segmented2">
        <toolkit:SegmentedItem Content="Item 4" />
        <toolkit:SegmentedItem Content="Item 5" />
        <toolkit:SegmentedItem Content="Item 6" />
    </toolkit:Segmented>

</StackPanel>

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

The left and right keyboard navigation behaves differently.

What is the new behavior?

The left and right keyboard navigation behaves the same.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • New component
    • Documentation has been added
    • Sample in sample app has been added
    • Analyzers are passing for documentation and samples
    • Icon has been created (if new sample) following the Thumbnail Style Guide and templates
  • Tests for the changes have been added (if applicable)
  • Header has been added to all new source files
  • Contains NO breaking changes

Other information

@michael-hawker
Copy link
Member

Thanks @AndrewKeepCoding for all these great fixes! 🦙❤️

QQ: I'm a bit confused at how removing the else is effecting the logic here, mind providing a bit more insight in how this fix is working or what the root cause here was?

@AndrewKeepCoding
Copy link
Contributor Author

AndrewKeepCoding commented Dec 18, 2025

As you can see below, MoveFocus() return value is assigned to e.Handled:

private void Segmented_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
    switch (e.Key)
    {
        case VirtualKey.Left: e.Handled = MoveFocus(MoveDirection.Previous); break;
        case VirtualKey.Right: e.Handled = MoveFocus(MoveDirection.Next); break;
    }
}

Previously, the else { retValue = true; } allowed MoveFocus(MoveDirection.Previous) to return true even when the focus was already on the first item. This behavior interfered with XYFocusKeyboardNavigation="Enabled", preventing it to work as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Segmented] Left arrow key not propagating to parent when at leftmost item

2 participants