Interpret enter as tab WPF

后端 未结 5 2039
醉酒成梦
醉酒成梦 2021-02-01 18:52

I want to interpret Enter key as Tab key in whole my WPF application, that is, everywhere in my application when user press Enter I want to focus the next focusable control,exce

5条回答
  •  生来不讨喜
    2021-02-01 19:21

    I got around woodyiii's issue by adding a FrameworkElement.Tag (whose value is IgnoreEnterKeyTraversal) to certain elements (buttons, comboboxes, or anything I want to ignore the enter key traversal) in my XAML. I then looked for this tag & value in the attached property. Like so:

        if (e.Key == Key.Enter)
        {
            if (ue.Tag != null && ue.Tag.ToString() == "IgnoreEnterKeyTraversal")
            {
                //ignore
            }
            else
            {
                e.Handled = true;
                ue.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            }
        }
    

提交回复
热议问题