Click here to Skip to main content
16,016,925 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I Want a Common solution for all form when I press Entry key on any Control the Cursor should be move to next Focusable control like tab. I don't want to write keydown event for all codes

What I have tried:

I have tried Writing single Keydown and assign to all the Windows or UserControl

C#
public void FrameworkElement_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            var _FrameworkElement = e.OriginalSource as FrameworkElement;
            if (e.Key == Key.Enter)
            {
                if(e.OriginalSource is Button) return;
                _FrameworkElement.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            }
        }
Posted
Updated 23-Oct-18 4:04am
v2

1 solution

That is not natural movement for a Windows application. Normally it is the TAB key.

However, to find you a solution, I did a quick Google search: wpf change tab key to enter key - Google Search[^] and found the following EnterKeyTraversal solution using attached behaviours: keyboard input - Interpret enter as tab WPF - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900