什么是WPF预览活动? [英] What are WPF Preview Events?

查看:87
本文介绍了什么是WPF预览活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找事件Preview ******的描述,因为每个元素都有事件KeyDown和PreviewKeyDown。有什么区别(不是一个附加的事件,一个不是,真正的传统差异和编程方式的区别)

I have been looking for descriptions of events "Preview******" like every element has events KeyDown and PreviewKeyDown. What is difference (not that one is attached event and one is not, the real conventional difference and programming way difference)

在派生自Control的任何类中,可以覆盖方法.. OnKeyDown和OnPreviewKeyDown,现在我正在编写我的自定义控件,我应该使用哪种方法?两者之间有什么区别。

In any class derived from Control, you can override both methods.. OnKeyDown and OnPreviewKeyDown, now I am writing my custom control, which method shall I use? And whats difference between both of them.

推荐答案

从编程WPF - Chris Sells和Ian Griffith

From Programming WPF - Chris Sells and Ian Griffith

除了直接事件,
WPF定义了
对中的大多数路由事件 - 一个隧道,另一个
冒泡。隧道事件名称
始终以预览开头,首先引用
。这给父母
的机会,在
到达孩子之前看到事件。这之后是
的冒泡对手。在大多数
的情况下,您将只处理
冒泡的一个。预览将是
通常用于

With the exception of direct events, WPF defines most routed events in pairs - one tunnelling and the other bubbling. The tunnelling event name always begins with 'Preview' and is raised first. This gives parents the chance to see the event before it reaches the child. This is followed by the bubbling counterpart. In most cases, you will handle only the bubbling one. The Preview would be usually used to


  • 阻止事件( e.Handled = true

  • 导致父母提前进行一般事件处理。

eg如果UI Tree = Button包含网格包含Canvas包含椭圆

单击椭圆将导致(MouseDownButton被Button删除,而Click则被提升。)

e.g. if UI Tree = Button contains Grid contains Canvas contains Ellipse
Clicking on the ellipse would result in (MouseDownButton is eaten up by Button and Click is raised instead.)

PreviewMouseDownButton
PreviewMouseDownGrid
PreviewMouseDownCanvas
PreviewMouseDownEllipse
MouseDownEllipse
MouseDownCanvas
MouseDownGrid

这篇关于什么是WPF预览活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆