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#
Developer technologies | 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.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 125.8K 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.