The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

UIElement.CaptureMouse Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Sets touch capture to a UIElement.

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

public bool CaptureMouse()

Return Value

Type: System.Boolean
Returns true if the object has touch capture; otherwise, returns false.

When an object is capturing touch input, that object receives touch input whether or not the user’s finger is within its bounding area. Touch input is typically only captured during simulated drag operations. To release touch capture, call the ReleaseMouseCapture method on the object that holds capture.

Touch input can be captured when all of the following conditions are true:

  • No other object is capturing touch input.

  • The user’s finger is physically touching the screen.

If one of these conditions is false, the CaptureMouse return value is false.

If an initial CaptureMouse call returned true and is successfully capturing touch input, subsequent calls to CaptureMouse on the same object will still return true unless conditions have changed; CaptureMouse returns nothing different if that object already had capture. Depending on your application's requirements, you might find it useful to set a variable that either tracks whether any object holds capture, or provides a reference to the specific object that currently has capture. If you use this technique, set the variable on each CaptureMouse call and clear it on each ReleaseMouseCapture call.

Only a UIElement derived object can capture touch input. Notable cases of other objects that have a visual character but cannot capture touch input are Run (only the parent TextBlock can capture) and geometries (only the parent Path can capture).

The UIElement that calls CaptureMouse must be hit test visible in the UI. This means that IsHitTestVisible cannot be false.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone