How to navigate between controls on KeyDown event.

David Simões 21 Reputation points
2021-08-19T15:57:34.337+00:00

I'm trying to have a KeyDown function that makes the focus move to the next control.

I've tried this but it throws me an error:

private void Obj_KeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key.ToString() == "Enter")  FocusManager.TryMoveFocus(FocusNavigationDirection.Down);
    }

Error:

System.Runtime.InteropServices.COMException: 'Catastrophic failure (0x8000FFFF (E_UNEXPECTED))'

Any hint on how can I make this work?

Thanks,
David

Developer technologies | Universal Windows Platform (UWP)
Windows development | Windows App SDK
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-08-19T17:41:32.727+00:00

    Check if a workaround works for you (https://github.com/microsoft/microsoft-ui-xaml/issues/5593):

    . . .
    var fneo = new FindNextElementOptions { SearchRoot = tb.XamlRoot.Content };
    FocusManager.TryMoveFocus(FocusNavigationDirection.Next, fneo);
    . . .
    

    Use an appropriate control for tb.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.