TouchDevice.Capture Method

Definition

Captures a touch to the specified element.

Overloads

Capture(IInputElement)

Captures a touch to the specified element by using the Element capture mode.

Capture(IInputElement, CaptureMode)

Captures a touch to the specified element by using the specified CaptureMode.

Capture(IInputElement)

Captures a touch to the specified element by using the Element capture mode.

C#
public bool Capture(System.Windows.IInputElement element);

Parameters

element
IInputElement

The element that captures the touch input.

Returns

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

Exceptions

Examples

The following example handles the TouchDown events that occur on a Canvas. When a touch is pressed on the Canvas, the TouchDevice is captured to the Canvas.

This example is part of a larger example that is available in the TouchDevice class overview.

C#
private void canvas_TouchDown(object sender, TouchEventArgs e)
{
    Canvas _canvas = (Canvas)sender as Canvas;
    if (_canvas != null)
    {
        _canvas.Children.Clear();
        e.TouchDevice.Capture(_canvas);

        // Record the ID of the first touch point if it hasn't been recorded.
        if (firstTouchId == -1)
            firstTouchId = e.TouchDevice.Id;
    }
}

Remarks

A TouchDevice cannot be captured to an element if it is already captured to another element.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Capture(IInputElement, CaptureMode)

Captures a touch to the specified element by using the specified CaptureMode.

C#
public bool Capture(System.Windows.IInputElement element, System.Windows.Input.CaptureMode captureMode);

Parameters

element
IInputElement

The element that captures the touch.

captureMode
CaptureMode

The capture policy to use.

Returns

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

Exceptions

Remarks

A TouchDevice cannot be captured to an element if it is already captured to another element.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10