ContentElement.OnPreviewKeyDown(KeyEventArgs) ContentElement.OnPreviewKeyDown(KeyEventArgs) ContentElement.OnPreviewKeyDown(KeyEventArgs) ContentElement.OnPreviewKeyDown(KeyEventArgs) Method

定義

當未處理的 PreviewKeyDown 附加事件到達其路由衍生自此類別的項目時,加以叫用。Invoked when an unhandled PreviewKeyDown attached event reaches an element in its route that is derived from this class. 實作這個方法可為此事件加入類別處理。Implement this method to add class handling for this event.

protected public:
 virtual void OnPreviewKeyDown(System::Windows::Input::KeyEventArgs ^ e);
protected internal virtual void OnPreviewKeyDown (System.Windows.Input.KeyEventArgs e);
abstract member OnPreviewKeyDown : System.Windows.Input.KeyEventArgs -> unit
override this.OnPreviewKeyDown : System.Windows.Input.KeyEventArgs -> unit
Protected Friend Overridable Sub OnPreviewKeyDown (e As KeyEventArgs)

參數

e
KeyEventArgs KeyEventArgs KeyEventArgs KeyEventArgs

包含事件資料的 KeyEventArgsThe KeyEventArgs that contains the event data.

備註

這個方法沒有預設的實值。This method has no default implementation. 由於繼承中的中繼類別可能會實作為這個方法, 因此建議您在您的執行中呼叫基底實作為。Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your implementation.

這個方法的目的類似于方法上通用語言執行平台 (CLR)common language runtime (CLR) *的事件模式: 這個方法會建立類別處理常式, 而不是實例處理常式, 藉此提供從衍生類別處理相符事件的方式。The purpose of this method is similar to the 通用語言執行平台 (CLR)common language runtime (CLR) event pattern On* methods: this method provides the means to handle the matching event from derived classes by establishing a class handler instead of an instance handler. 在此情況下, 比對事件是路由事件。In this case the matching event is a routed event. 因為路由事件可以由子*元素引發, 而不一定是將叫用處理程式的專案, 所以 On 方法的實作為模式會不同。The implementation pattern of the On* methods is different for routed events because a routed event can be raised by a child element, which is not necessarily the element that will invoke handlers. 因此, 您的執行需要檢查事件資料的來源屬性。Therefore, your implementation needs to examine the source properties of the event data. 在大部分情況下, 它不應該嘗試 reraise 事件。It should not try to reraise the event in most cases.

藉由覆寫這個方法或向RegisterClassHandler註冊類別處理常式, 的ContentElement衍生類別可以在事件路由收到事件時, 呼叫私用類別處理常式方法。Either by overriding this method or by registering class handlers with RegisterClassHandler, derived classes of ContentElement can call private class handler methods when the event is received along the event route. 適當處理類別的其中一個案例是操作事件資料, 並將路由事件標示為已處理。One scenario where class handling is appropriate is to manipulate the event data and mark the routed event as handled. 特別針對預覽事件的另一個案例是將它們標示為已處理, 以便不叫用相符的反升類處理常式。Another scenario that is specifically for Preview events is to mark them handled so that the matching bubbling class handlers are not invoked.

適用於

另請參閱