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

Universal Windows Platform (UWP)
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
830 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,317 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 120.1K 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.