获取当前控件的下一个控件,回车切换到下一个控件

 
 
        private void tb_unit_name_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                // MoveFocus takes a TraveralReqest as its argument.
                TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);

                // Gets the element with keyboard focus.
                UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;

                // Change keyboard focus.
                if (elementWithFocus != null)
                {
                    elementWithFocus.MoveFocus(request);
                }
                e.Handled = true;
            UIElement nextElement = Keyboard.FocusedElement as UIElement;
            if (nextElement is TextBox)
            {
                (nextElement as TextBox).SelectAll();
            }

            }
            base.OnKeyDown(e);


        }


这里获取了下一个控件 这时如果焦点要返回上一个控件自行修改。

你可能感兴趣的:(获取当前控件的下一个控件,回车切换到下一个控件)