How do I simulate a Tab key press when Return is pressed in a WPF application?

后端 未结 7 2053
悲哀的现实
悲哀的现实 2021-01-01 16:37

In a WPF application, i have a window that has a lot of fields. When the user uses the TAB key after filling each field, windows understands that it moves on to the next. Th

7条回答
  •  渐次进展
    2021-01-01 16:40

    You can look at a post here: http://social.msdn.microsoft.com/Forums/en/wpf/thread/c85892ca-08e3-40ca-ae9f-23396df6f3bd

    Here's an example:

    private void textBox1_PreviewKeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Enter)
                {
                    TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
                    request.Wrapped = true;
                    ((TextBox)sender).MoveFocus(request);
                }
            }
    

提交回复
热议问题