Mouse.PreviewMouseDown Mouse.PreviewMouseDown Mouse.PreviewMouseDown Attached Event

定義

發生於按下任何滑鼠按鍵時。Occurs when any mouse button is depressed.

see AddPreviewMouseDownHandler, and RemovePreviewMouseDownHandler
see AddPreviewMouseDownHandler, and RemovePreviewMouseDownHandler
see AddPreviewMouseDownHandler, and RemovePreviewMouseDownHandler

備註

按下哪一個滑鼠按鍵是藉由檢查事件的引數來判斷。Which mouse button was depressed is determined by checking the arguments of the event. 這是附加事件 (使用通道路由策略), 其目的是要讓接受輸入的現有使用者介面 (UI)user interface (UI)元素參考附加事件語法。This is an attached event (using tunneling routing strategy) that is intended through attached event syntax to be referenced by existing 使用者介面 (UI)user interface (UI) elements that take input.

這是附加事件。This is an attached event. WPFWPF將附加事件實作為路由事件。implements attached events as routed events. 附加事件基本上是參考XAMLXAML事件的一種語言概念, 可以在未定義該事件的物件上處理, 這WPFWPF也會讓事件通過路由來進行擴充。Attached events are fundamentally a XAMLXAML language concept for referencing events that can be handled on objects that do not define that event, which WPFWPF expands upon by also enabling the event to traverse a route. 附加事件在程式碼中沒有直接處理語法;若要在程式碼中附加路由事件的處理常式, 您可以使用指定的 Add * 處理常式方法。Attached events do not have a direct handling syntax in code; to attach handlers for a routed event in code, you use a designated Add*Handler method. 如需詳細資訊, 請參閱附加事件總覽For details, see Attached Events Overview.

UIElement 通用語言執行平台 (CLR)common language runtime (CLR) PreviewMouseRightButtonDown PreviewMouseLeftButtonDown架構會在這個附加事件上建立, 其方式是在上將它呈現為兩個不同的事件: 和。 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)The Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) framework builds on this attached event by surfacing it as two different 通用語言執行平台 (CLR)common language runtime (CLR) events on UIElement: PreviewMouseLeftButtonDown and PreviewMouseRightButtonDown. 這些執行會處理基礎PreviewMouseDown事件並讀取事件的引數, 以判斷是否牽涉到左或右滑鼠按鍵。These implementations handle the underlying PreviewMouseDown event and read the arguments of the event to determine whether the left or right mouse button was involved. 針對三個按鈕, 中間按鈕沒有架構層級的事件支援, 而且您應該使用PreviewMouseDown事件並檢查事件引數中的置中按鈕條件。For three-button, there is no framework-level event support for the center button, and you should use the PreviewMouseDown event and check for the center button condition in the event arguments.

對於與滑鼠相關的路由事件, 請小心如何或何時將它們標示為已處理。For routed events that relate to the mouse, be careful about how or when you mark them handled. 處理位於根附近的事件, 並進一步處理來源的子系, 可能不適合複合控制項, 其中的組合部分可能會有預期的滑鼠行為。Handling the event near the root and handling it by a child further toward the source may not be appropriate for composited controls, where the compositing pieces might have expected mouse behaviors. 做出適當選擇是否也應該知道是否有任何指定的滑鼠動作, 是WPFWPF因為架構選擇了讓基礎Mouse路由事件呈現為CLRCLR沿著路由的事件。The difficulty in making the appropriate choices about whether other elements should also be informed about any given mouse action is in fact why the WPFWPF framework chose the model of having the underlying Mouse routed event be surfaced as CLRCLR events along the route.

路由事件資訊Routed Event Information

識別碼欄位Identifier field PreviewMouseDownEvent
路由策略Routing strategy 建立Tunneling
Delegate - 委派Delegate MouseButtonEventHandler

適用於