ContentElement.OnMouseDown(MouseButtonEventArgs) ContentElement.OnMouseDown(MouseButtonEventArgs) ContentElement.OnMouseDown(MouseButtonEventArgs) ContentElement.OnMouseDown(MouseButtonEventArgs) Method

定義

當未處理的 MouseDown 附加事件到達其路由中衍生自此類別的項目時叫用。Invoked when an unhandled MouseDown 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 OnMouseDown(System::Windows::Input::MouseButtonEventArgs ^ e);
protected internal virtual void OnMouseDown (System.Windows.Input.MouseButtonEventArgs e);
abstract member OnMouseDown : System.Windows.Input.MouseButtonEventArgs -> unit
override this.OnMouseDown : System.Windows.Input.MouseButtonEventArgs -> unit
Protected Friend Overridable Sub OnMouseDown (e As MouseButtonEventArgs)

參數

e
MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs

包含事件資料的 MouseButtonEventArgsThe MouseButtonEventArgs that contains the event data. 此事件資料會報告有關按下的滑鼠按鈕以及已處理狀態的詳細資訊。This event data reports details about the mouse button that was pressed and the handled state.

備註

滑鼠按鈕的動作也是由專用的輸入管理員處理。Mouse button actions are also handled by a dedicated input manager. 其他可依賴滑鼠按鈕的動作,例如輸入和命令繫結的程式設計功能可能會叫用動作的處理常式之前它會公開為一般的滑鼠按鈕動作。Other programming features that rely on mouse button actions, such as input and command bindings, might invoke handlers for the action before it is exposed as a general mouse button action. 如果這些輸入系統功能 markMouse.MouseDown為已處理的事件OnMouseDown不會叫用。If these input system features mark the Mouse.MouseDown event as handled, OnMouseDown is not invoked.

如果您使用這個類別處理常式將事件標示為已處理時,可能會影響下列事件:MouseLeftButtonDownMouseRightButtonDownIf you use this class handler to mark the event as handled, you potentially impact the following events: MouseLeftButtonDown and MouseRightButtonDown. 其中一個這些事件可能會發生在接收端的項目上時Mouse.MouseDown收到。Either of these events may be raised on the receiving element when Mouse.MouseDown is received.

如果您將標示為已處理的類別中處理這個事件時,仍然會引發子;不過,它們會傳遞事件資料中的處理的狀態。If you mark this event as handled in class handling, subevents are still raised; however, they pass the handled state in the event data. 如果類別處理在處理事件,副的執行個體處理常式不會叫用除非您明確地使用AddHandler(RoutedEvent, Delegate, Boolean)具有handledEventsToo``true才能附加處理常式。If the event is handled in class handling, instance handlers for the subevents are not invoked unless you explicitly use AddHandler(RoutedEvent, Delegate, Boolean) with handledEventsToo true in order to attach handlers. 類別處理常式也不會叫用除非那些類別處理常式向RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean)簽章handledEventsToo trueClass handlers also are not invoked unless those class handlers were registered with the RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean) signature with handledEventsToo true. 藉由處理OnMouseDown,當其中隱含類別處理負責動作下的所有可能的滑鼠按鈕。By handling OnMouseDown, you are implying that your class handling accounted for all possible mouse button down actions. 此行為可能會不必要的;因此,小心時將事件標記為已處理的情況下,您在使用這個虛擬方法。This behavior might be unwanted; therefore, use caution when you use this virtual method to mark events as handled.

每個特定按鈕的直接事件也有虛擬機器*方法; 請考慮是否覆寫這些特定按鈕的類別處理常式可能更適合。Each of the button-specific direct events also has a virtual On* method; consider whether overriding these button-specific class handlers might be more appropriate.

這個方法沒有任何預設實作。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. 它不應該嘗試重新引發此事件,在大部分情況下。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.

適用於

另請參閱