TouchDevice.Capture 方法

定義

Captures a touch to the specified element.Captures a touch to the specified element.

多載

Capture(IInputElement)

Captures a touch to the specified element by using the Element capture mode.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.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.Captures a touch to the specified element by using the Element capture mode.

public:
 bool Capture(System::Windows::IInputElement ^ element);
public bool Capture (System.Windows.IInputElement element);
member this.Capture : System.Windows.IInputElement -> bool
Public Function Capture (element As IInputElement) As Boolean

參數

element
IInputElement

The element that captures the touch input.The element that captures the touch input.

傳回

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

例外狀況

範例

下列範例會處理 Canvas上發生的 TouchDown 事件。The following example handles the TouchDown events that occur on a Canvas. 當按下 Canvas的觸控時,會將 TouchDevice 捕獲至 CanvasWhen a touch is pressed on the Canvas, the TouchDevice is captured to the Canvas.

這個範例是 TouchDevice 類別總覽中提供之較大範例的一部分。This example is part of a larger example that is available in the TouchDevice class overview.

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;
    }
}
' Touch Down
Private Sub canvas_TouchDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.TouchEventArgs)
    Dim _canvas As Canvas = CType(sender, Canvas)
    If (_canvas IsNot Nothing) Then
        _canvas.Children.Clear()
        e.TouchDevice.Capture(_canvas)

        ' Record the ID of the first touch point if it hasn't been recorded.
        If firstTouchId = -1 Then
            firstTouchId = e.TouchDevice.Id
        End If
    End If
End Sub

備註

如果 TouchDevice 已捕捉至另一個專案,則無法將其捕捉至元素。A TouchDevice cannot be captured to an element if it is already captured to another element.

Capture(IInputElement, CaptureMode)

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

public:
 bool Capture(System::Windows::IInputElement ^ element, System::Windows::Input::CaptureMode captureMode);
public bool Capture (System.Windows.IInputElement element, System.Windows.Input.CaptureMode captureMode);
member this.Capture : System.Windows.IInputElement * System.Windows.Input.CaptureMode -> bool
Public Function Capture (element As IInputElement, captureMode As CaptureMode) As Boolean

參數

element
IInputElement

The element that captures the touch.The element that captures the touch.

captureMode
CaptureMode

The capture policy to use.The capture policy to use.

傳回

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

例外狀況

備註

如果 TouchDevice 已捕捉至另一個專案,則無法將其捕捉至元素。A TouchDevice cannot be captured to an element if it is already captured to another element.

適用於