路由事件(鼠标路由事件+键盘路由事件)
Posted changbaishan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了路由事件(鼠标路由事件+键盘路由事件)相关的知识,希望对你有一定的参考价值。
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);
}
以上是关于路由事件(鼠标路由事件+键盘路由事件)的主要内容,如果未能解决你的问题,请参考以下文章