แก้ไข

แชร์ผ่าน


ContentElement.OnPreviewMouseLeftButtonDown(MouseButtonEventArgs) Method

Definition

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.

protected public:
 virtual void OnPreviewMouseLeftButtonDown(System::Windows::Input::MouseButtonEventArgs ^ e);
protected internal 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 Friend Overridable Sub OnPreviewMouseLeftButtonDown (e As MouseButtonEventArgs)

Parameters

e
MouseButtonEventArgs

The MouseButtonEventArgs that contains the event data. The event data reports that the left mouse button was pressed.

Remarks

The PreviewMouseLeftButtonDown event appears to travel a tunneling route but actually travels in an indirect way. Mouse.PreviewMouseDown is the underlying event that is tunnel routed, and each ContentElement along the event route uses identical handling to raise the direct routed event 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. 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.

The default implementation for general mouse event handling in ContentElement 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. In the static constructor of your derived class, register an alternative class handler for Mouse.PreviewMouseDown. You cannot change the mouse handling behavior of ContentElement 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. Failing to call base disables default input handling for that mouse event on ancestor classes that also expect to invoke OnPreviewMouseLeftButtonDown. 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.

Applies to