EN
本內容沒有您的語言版本,但有英文版本。

UIElement.CaptureMouse Method

July 28, 2014

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

顯示:
© 2014 Microsoft