TouchDevice.Capture 方法

定義

擷取對指定之項目的觸控。Captures a touch to the specified element.

多載

Capture(IInputElement)

使用 Element 擷取模式,擷取對指定之項目的觸控。Captures a touch to the specified element by using the Element capture mode.

Capture(IInputElement, CaptureMode)

使用指定的 CaptureMode 擷取對指定之項目的觸控。Captures a touch to the specified element by using the specified CaptureMode.

Capture(IInputElement)

使用 Element 擷取模式,擷取對指定之項目的觸控。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.

傳回

如果項目可以擷取觸控則為 true,否則為 falsetrue if the element was able to capture the touch; otherwise, false.

例外狀況

element 不是 UIElementUIElement3D,也不是 ContentElementelement is not a UIElement, UIElement3D, or ContentElement.

範例

下列範例會處理 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)

使用指定的 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.

captureMode
CaptureMode

要使用的捕捉原則。The capture policy to use.

傳回

如果項目可以擷取觸控則為 true,否則為 falsetrue if the element was able to capture the touch; otherwise, false.

例外狀況

element 不是 UIElementUIElement3D,也不是 ContentElementelement is not a UIElement, UIElement3D, or ContentElement.

備註

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

適用於