ContentElement.OnPreviewMouseDown(MouseButtonEventArgs) ContentElement.OnPreviewMouseDown(MouseButtonEventArgs) ContentElement.OnPreviewMouseDown(MouseButtonEventArgs) ContentElement.OnPreviewMouseDown(MouseButtonEventArgs) Method

定義

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

參數

e
MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs MouseButtonEventArgs

包含事件資料的 MouseButtonEventArgsThe MouseButtonEventArgs that contains the event data. 事件資料會報告一個或多個滑鼠按鈕已按下。The event data reports that one or more mouse buttons were pressed.

備註

滑鼠按鍵動作也會由專用的輸入管理員處理。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. 如果這些輸入系統功能將Mouse.PreviewMouseDown事件標示為已處理, OnPreviewMouseDown則不會叫用。If these input system features mark the Mouse.PreviewMouseDown event as handled, OnPreviewMouseDown is not invoked.

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

如果您在類別處理中將此事件標示為已處理, 則仍然會引發 subevents。不過, 它們會在事件資料中傳遞已處理的狀態。If you mark this event as handled in class handling, subevents are still raised; however, they pass the handled state in the event data. 如果事件是在類別處理中處理, 則不會叫用 subevents 的實例處理常式, 除非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 true這些類別處理常式。Class handlers also are not invoked unless those class handlers were registered with the RegisterClassHandler(Type, RoutedEvent, Delegate, Boolean) signature with handledEventsToo true. 藉由OnPreviewMouseDown處理, 您就表示您的類別處理會納入所有可能的滑鼠按鍵關閉動作。By handling OnPreviewMouseDown, 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.

每個按鈕特定的直接事件也有虛擬的 On*方法, 請考慮是否要覆寫這些按鈕特定的類別處理常式是否更適當。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. 在大部分情況下, 它不應該嘗試 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.

適用於

另請參閱