UIElement.PreviewKeyDown Event


当焦点在该元素上时按下某个键后发生。Occurs when a key is pressed while focus is on this element.

 virtual event System::Windows::Input::KeyEventHandler ^ PreviewKeyDown;
public event System.Windows.Input.KeyEventHandler PreviewKeyDown;
member this.PreviewKeyDown : System.Windows.Input.KeyEventHandler 
Public Custom Event PreviewKeyDown As KeyEventHandler 



键处理与其他平台功能(如命令和文本撰写)交互。Key handling interacts with other platform features such as commanding and text composition. KeyDown 事件是较低级别的文本输入事件,可能不会在某些控件上按预期方式工作。The KeyDown event is a lower-level text input event that might not behave as expected on certain controls. 这是因为某些控件具有控件组合或类处理,可提供较高级别的文本输入处理和相关事件。This is because some controls have control compositing or class handling that provides a higher-level version of text input handling and related events.

此事件创建此类的 Keyboard.PreviewKeyDown 附加事件的别名,以便在将 UIElement 作为基元素继承时,PreviewKeyDown 是类成员列表的一部分。This event creates an alias for the Keyboard.PreviewKeyDown attached event for this class, so that PreviewKeyDown is part of the class members list when UIElement is inherited as a base element. 附加到 PreviewKeyDown 事件的事件处理程序附加到基础 Keyboard.PreviewKeyDown 附加事件,并接收相同的事件数据实例。Event handlers that are attached to the PreviewKeyDown event are attached to the underlying Keyboard.PreviewKeyDown attached event and receive the same event data instance.

路由事件信息Routed Event Information

标识符字段Identifier field PreviewKeyDownEvent
路由策略Routing strategy 隧道Tunneling
委托Delegate KeyEventHandler
  • 对应的冒泡事件 KeyDownThe corresponding bubbling event is KeyDown.

  • 重写 OnPreviewKeyDown 在派生类中实现此事件的类处理。Override OnPreviewKeyDown to implement class handling for this event in derived classes.

Applies to

See also