MouseDevice.Capture Method (IInputElement)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Captures mouse events to the specified element.

Namespace:   System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)

public bool Capture(
	IInputElement element


Type: System.Windows.IInputElement

The element to capture the mouse.

Return Value

Type: System.Boolean

true if the element was able to capture the mouse; otherwise, false.

Exception Condition

element is not a UIElement or ContentElement.

When an element captures the mouse, it receives mouse input whether the cursor is within its borders

If a CaptureMode is not specified, the default CaptureMode is Element.

To release mouse capture, call Capture passing null as the element to capture.

If the mouse is captured when a MouseDown or MouseUp event is raised and the input is not going to the element underneath the mouse, PreviewMouseDownOutsideCapturedElement and PreviewMouseUpOutsideCapturedElement are raised first. This enables the captured element a chance to release capture before the MouseDown and MouseUp events are routed.

.NET Framework
Available since 3.0
Return to top