路由事件(鼠标路由事件+键盘路由事件)

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);
        }

转载于:https://www.cnblogs.com/changbaishan/p/9355900.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值