UIElement.KeyDown 事件


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

 virtual event System::Windows::Input::KeyEventHandler ^ KeyDown;
public event System.Windows.Input.KeyEventHandler KeyDown;
member this.KeyDown : System.Windows.Input.KeyEventHandler 
Public Custom Event KeyDown 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.KeyDown 附加事件的别名,以便在将 UIElement 作为基元素继承时,KeyDown 是类成员列表的一部分。This event creates an alias for the Keyboard.KeyDown attached event for this class so that KeyDown is part of the class members list when UIElement is inherited as a base element. 附加到 KeyDown 事件的事件处理程序附加到基础 Keyboard.KeyDown 附加事件,并接收相同的事件数据实例。Event handlers that are attached to the KeyDown event are attached to the underlying Keyboard.KeyDown attached event and receive the same event data instance.

路由事件信息Routed Event Information

标识符字段Identifier field KeyDownEvent
路由策略Routing strategy 冒泡Bubbling
委托Delegate KeyEventHandler
  • 对应的隧道事件 PreviewKeyDownThe corresponding tunneling event is PreviewKeyDown.

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