ContentElement.OnPreviewMouseRightButtonDown(MouseButtonEventArgs) 方法

定義

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

參數

e
MouseButtonEventArgs

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

備註

PreviewMouseRightButtonDown 事件會顯示為移動通道路由,但實際上是以間接方式移動。The PreviewMouseRightButtonDown event appears to travel a tunneling route but actually travels in an indirect way. Mouse.PreviewMouseDown 是以通道路由傳送的基礎事件,而每個 ContentElement 沿著事件路由都會使用相同的處理,來引發直接路由事件 MouseRightButtonDownMouse.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 MouseRightButtonDown. 雖然您可以將此專案的 PreviewMouseRightButtonDown 事件標示為已處理,但已處理的狀態並不會沿著事件路由永久保存至其他元素。Although you can mark the PreviewMouseRightButtonDown 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.

ContentElement 中一般滑鼠事件處理的預設執行會接聽 Mouse.PreviewMouseDown,並將它轉換為適當的本機事件。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. 在衍生類別的靜態函式中,註冊 Mouse.PreviewMouseDown的替代類別處理常式。In the static constructor of your derived class, register an alternative class handler for Mouse.PreviewMouseDown. 您無法藉由覆寫 OnPreviewMouseRightButtonDown來變更 ContentElement 的滑鼠處理行為。You cannot change the mouse handling behavior of ContentElement by overriding OnPreviewMouseRightButtonDown.

或者,您可以覆寫這個方法,以便變更特定滑鼠狀態的事件處理。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. 無法呼叫基底會停用在上階類別上該滑鼠事件的預設輸入處理,也預期會叫用 OnPreviewMouseRightButtonDownFailing to call base disables default input handling for that mouse event on ancestor classes that also expect to invoke OnPreviewMouseRightButtonDown. 例如,您可以從 Control 衍生,並覆寫衍生類別中的 OnPreviewMouseRightButtonDown,而不需要呼叫 base;不過,此覆寫會停用控制項上的內容功能表服務,這是 Control 預設行為的一部分。For example, you can derive from Control and override OnPreviewMouseRightButtonDown in your derived class without calling base; however, this override disables the context menu services on your control, which are part of the Control default behavior.

適用於