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.

傳回

Boolean

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

例外狀況

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

範例

下列範例 TouchDown 會處理在上發生的事件 CanvasThe 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.

這個範例是類別總覽中提供之較大範例的一部分 TouchDeviceThis 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.

傳回

Boolean

如果項目可以擷取觸控則為 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.

適用於