码迷,mamicode.com
首页 > 其他好文 > 详细

WPF 回车转Tab实现跳转

时间:2014-08-31 10:26:51      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   div   cti   log   sp   on   new   

1.重写窗体的KeyDown事件

    protected override void OnKeyDown(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;
        }
        base.OnKeyDown(e);
    }

 2.在基容器如Grid的KeyDown事件中

    private void Grid_KeyDown(object sender, KeyEventArgs e)
    {
        var uie = e.OriginalSource as UIElement;
        if (e.Key == Key.Enter)
        {
            uie.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            e.Handled = true;
        }
    }

 

WPF 回车转Tab实现跳转

标签:blog   io   ar   div   cti   log   sp   on   new   

原文地址:http://www.cnblogs.com/babietongtianta/p/3947353.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!