Enter/Esc Hot Key Silverlight

来源:转载

客户要求所有childwindow支持 Key.Enter,Key.Escape 代替click ok/cancel btn. 用下面的方法能快速完成

public class HotKeyManager    {
        public static void RegistKeyEventHandler(UIElement control, RoutedEventHandler okHanlder, RoutedEventHandler cancelHanlder)
        {
            control.KeyDown += (s, e) => 
            {
                if (e.Key == Key.Escape)
                {
                    cancelHanlder(s, e);
                }
                else if (e.Key == Key.Enter)
                {
                    okHanlder(s, e);
                }
            };
        }
    }

调用代码

HotKeyManager.RegistKeyEventHandler(YourChildWindow, OKButton_Click, CancelButton_Click)

本文来自mjg的博客,原文地址:http://www.cnblogs.com/mjgb/archive/2011/06/29/2093339.html


分享给朋友:
您可能感兴趣的文章:
随机阅读: