WPF笔记-路由事件

添加处理路由事件 两种方法

1.XAML

<Image Source="happyface.jpg" Stretch="None"

Name="img" MOuseUp="img_MouseUp" />

<Button Click="cmdOK_Click">OK</Button>


2.c#

img.MouseUp += new MouseButtonEventHandler(img_MouseUp);

OR

img.AddHandler(UIElement.MouseUpEvent,new MouseButtenEventHandler(img_MouseUp));

断开:

img.MouseUp -= ima_MouseUp;

这里UIElement是基础类,定义了类似MouseDown的事件。被所有UI控件继承。


混合嵌套标签的统一事件路由

Direct event / Bubbling event / tunneling event

MouseUp/Down等属于冒泡路游事件


从RoutedEventArgs类中可以知道下面参数

1.e.Source 2.originalSource  


挂起事件

cmdClear.AddHander(UIElement.MouseUpEvent,

  new MouseButtonEventHandler(cmdClear_MouseUp),true);


隧道路由事件

以preview开头,有一个bubbling路由 就会有一个tunneling event事件

当一个按键按下时,首先是窗口触发,然后在生和层次中向下传递。如果在任何位置将

previewkeyDonw事件标记为已处理,则不会有冒泡事件发生。


事件:

生命周期事件

Initialized

Loaded

Unloaded

SourceInitialized

ContentRendered

Activated

Deactivated

Closing

Closed


鼠标事件

键盘事件

PreviewKeyDown

KeyDown

PreviewTextInput

TextInput

PreviewKeyUp

KeyUp

手写笔事件

多点触摸事件


焦点

UIElement Focusable属性。


捕获鼠标

Mouse.Capture()




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值