UIElement.OnPreviewMouseLeftButtonDown(MouseButtonEventArgs) 方法


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

 virtual void OnPreviewMouseLeftButtonDown(System::Windows::Input::MouseButtonEventArgs ^ e);
protected virtual void OnPreviewMouseLeftButtonDown (System.Windows.Input.MouseButtonEventArgs e);
abstract member OnPreviewMouseLeftButtonDown : System.Windows.Input.MouseButtonEventArgs -> unit
override this.OnPreviewMouseLeftButtonDown : System.Windows.Input.MouseButtonEventArgs -> unit
Protected Overridable Sub OnPreviewMouseLeftButtonDown (e As MouseButtonEventArgs)



包含事件資料的 MouseButtonEventArgsThe MouseButtonEventArgs that contains the event data. 事件資料會報告滑鼠左鍵已按下。The event data reports that the left mouse button was pressed.


PreviewMouseLeftButtonDown 事件看似傳送通道路由,但實際上是以間接方式傳送。The PreviewMouseLeftButtonDown event appears to travel a tunneling route but actually travels in an indirect way. Mouse.PreviewMouseDown 是通道路由的基礎事件,而每個事件 UIElement 路由沿著事件路由都會使用相同的處理來引發直接路由事件 PreviewMouseLeftButtonDownMouse.PreviewMouseDown is the underlying event that is tunnel routed, and each UIElement along the event route uses identical handling to raise the direct routed event PreviewMouseLeftButtonDown. 雖然您可以將此事件標示為已 PreviewMouseLeftButtonDown 處理,但處理的狀態並不會沿著事件路由永久保存至其他元素。Although you can mark the PreviewMouseLeftButtonDown event as handled for purposes of this element, the handled state does not perpetuate to other elements along the event route. 不過,您可能會想要將事件標示為已處理,以防止一般的實例處理常式 (未指定 handledEventsToo) 的呼叫。However, you might want to mark the event as handled in order to prevent general instance handlers (those that did not specify handledEventsToo) from being invoked.

中一般滑鼠事件處理的預設執行 UIElement Mouse.PreviewMouseDown 會接聽,並將其轉換為適當的本機事件。The default implementation for general mouse event handling in UIElement listens for Mouse.PreviewMouseDown and converts it to an appropriate local event. 如果您想要覆寫此邏輯,則必須建立衍生類別。If you want to override this logic, you must create a derived class. 在衍生類別的靜態函式中,註冊的替代類別處理常式 Mouse.PreviewMouseDownIn the static constructor of your derived class, register an alternative class handler for Mouse.PreviewMouseDown. 您無法藉由覆寫來變更的滑鼠處理行為 UIElement OnPreviewMouseLeftButtonDownYou cannot change the mouse handling behavior of UIElement by overriding OnPreviewMouseLeftButtonDown.

或者,您可以覆寫這個方法,以便變更特定滑鼠狀態的事件處理。Alternatively, you can override this method in order to change event handling for a specific mouse state. 您是否選擇呼叫基底執行取決於您的案例。Whether you choose to call the base implementation depends on your scenario. 無法呼叫基底會針對也預期叫用的上階類別,停用該滑鼠事件的預設輸入處理 OnPreviewMouseLeftButtonDownFailing to call base disables default input handling for that mouse event on ancestor classes that also expect to invoke OnPreviewMouseLeftButtonDown. 例如,您可以 Button 在衍生類別中衍生和覆寫, OnPreviewMouseLeftButtonDown 而不需要呼叫基底實值; 不過,此覆寫會停用 Click 事件。For example, you can derive from Button and override OnPreviewMouseLeftButtonDown in your derived class without calling the base implementation; however, this override disables the Click event.