zoukankan      html  css  js  c++  java
  • 路由事件(鼠标路由事件+键盘路由事件)

    1:常规的鼠标路由事件定义:

            #region 路由事件
            public static readonly RoutedEvent CrossIconClickedEvent = EventManager.RegisterRoutedEvent("CrossIconClicked",
                RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(FilterLabel));
            #endregion

           #region CLR事件
            public event RoutedEventHandler CrossIconClicked
            {
                add { this.AddHandler(CrossIconClickedEvent, value); }
                remove { this.RemoveHandler(CrossIconClickedEvent, value); }
            }
            #endregion

    #region 私有方法
            /// <summary>
            /// 点击删除图标,引发CrossIconClicked事件
            /// </summary>
            private void ImageDel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
            {
                //引发路由事件
                RoutedEventArgs newEvent = new RoutedEventArgs(FilterLabel.CrossIconClickedEvent, this);
                this.RaiseEvent(newEvent);
            }
            #endregion

    2:键盘路由事件定义

     #region 路由事件
            public static readonly RoutedEvent FreeKeyDownEvent = EventManager.RegisterRoutedEvent("FreeKeyDown",
                RoutingStrategy.Bubble, typeof(KeyEventHandler), typeof(FreeDatePicker));
            #endregion

    #region CLR事件
            //
            // 摘要:
            //     在焦点位于此元素上并且用户按下键时发生。
            public event KeyEventHandler FreeKeyDown
            {
                add { this.AddHandler(FreeKeyDownEvent, value); }
                remove { this.RemoveHandler(FreeKeyDownEvent, value); }
            }
            #endregion

    /// <summary>
            /// 触发FreeKeyDown事件(非鼠标的键盘路由事件)
            /// </summary>
            private void Date_TextBox_KeyDown(object sender, KeyEventArgs e)
            {
                KeyEventArgs newEvent = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, e.Key);
                newEvent.RoutedEvent = FreeDatePicker.FreeKeyDownEvent;
                this.RaiseEvent(newEvent);
            }

  • 相关阅读:
    贪心法之最优装载问题
    判断回文
    P1217 [USACO1.5]回文质数 Prime Palindromes
    李白打酒
    P1036 选数
    P1028 数的计算
    P1316 丢瓶盖
    P1181 数列分段Section I
    P1182 数列分段`Section II`
    P1216 [IOI1994][USACO1.5]数字三角形 Number Triangles
  • 原文地址:https://www.cnblogs.com/changbaishan/p/9355900.html
Copyright © 2011-2022 走看看