TouchDevice Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta un singolo input tocco prodotto da un dito su un touchscreen.
public ref class TouchDevice abstract : System::Windows::Input::InputDevice, System::Windows::Input::IManipulator
public abstract class TouchDevice : System.Windows.Input.InputDevice, System.Windows.Input.IManipulator
type TouchDevice = class
inherit InputDevice
interface IManipulator
Public MustInherit Class TouchDevice
Inherits InputDevice
Implements IManipulator
- Ereditarietà
- Implementazioni
Esempio
L'esempio seguente consente di creare modelli semplici su un Canvas oggetto trascinando due dita su un touchscreen. Ogni tocco è rappresentato da un TouchDevice oggetto nell'oggetto TouchEventArgs. Il motivo viene creato disegnando una linea tra i punti di tocco forniti dai tocchi. Questo esempio richiede uno schermo compatibile con Windows Touch.
Il markup seguente crea l'interfaccia utente, costituita da un Canvas oggetto centrato in una griglia e associa i gestori eventi per gli eventi di tocco.
<Window x:Class="WpfTouchEventsSample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="525" Width="525">
<Grid>
<Canvas x:Name="canvas1"
Width="500" Height="500"
Background="Black"
TouchDown="canvas_TouchDown"
TouchMove="canvas_TouchMove"
TouchUp="canvas_TouchUp" />
</Grid>
</Window>
Il codice seguente gestisce gli eventi di tocco. Quando si preme un tocco su Canvas, l'oggetto TouchDevice viene acquisito in Canvas. Quando il tocco viene sollevato, l'oggetto TouchDevice viene rilasciato. Quando un tocco si sposta su Canvas, viene controllato .Id Se lo spostamento proviene dal primo tocco, viene registrata la posizione. Se lo spostamento proviene dal secondo tocco, una linea viene disegnata dalla posizione del primo tocco alla posizione del secondo tocco.
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;
namespace WpfTouchEventsSample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
// Variables to track the first two touch points
// and the ID of the first touch point.
private Point pt1, pt2 = new Point();
private int firstTouchId = -1;
public MainWindow()
{
InitializeComponent();
}
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;
}
}
private void canvas_TouchMove(object sender, TouchEventArgs e)
{
Canvas _canvas = (Canvas)sender as Canvas;
if (_canvas != null)
{
TouchPoint tp = e.GetTouchPoint(_canvas);
// This is the first touch point; just record its position.
if (e.TouchDevice.Id == firstTouchId)
{
pt1.X = tp.Position.X;
pt1.Y = tp.Position.Y;
}
// This is not the first touch point; draw a line from the first point to this one.
else if (e.TouchDevice.Id != firstTouchId)
{
pt2.X = tp.Position.X;
pt2.Y = tp.Position.Y;
Line _line = new Line();
_line.Stroke = new RadialGradientBrush(Colors.White, Colors.Black);
_line.X1 = pt1.X;
_line.X2 = pt2.X;
_line.Y1 = pt1.Y;
_line.Y2 = pt2.Y;
_line.StrokeThickness = 2;
_canvas.Children.Add(_line);
}
}
}
private void canvas_TouchUp(object sender, TouchEventArgs e)
{
Canvas _canvas = (Canvas)sender as Canvas;
if (_canvas != null && e.TouchDevice.Captured == _canvas)
{
_canvas.ReleaseTouchCapture(e.TouchDevice);
}
}
}
}
Class MainWindow
' Variables to track the first two touch points
' and the ID of the first touch point.
Private pt1, pt2 As Point
Private firstTouchId As Integer = -1
' 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
' Touch Move
Private Sub canvas_TouchMove(ByVal sender As System.Object, ByVal e As System.Windows.Input.TouchEventArgs)
Dim _canvas As Canvas = CType(sender, Canvas)
If (_canvas IsNot Nothing) Then
Dim tp = e.GetTouchPoint(_canvas)
' This is the first touch point; just record its position.
If e.TouchDevice.Id = firstTouchId Then
pt1.X = tp.Position.X
pt1.Y = tp.Position.Y
' This is not the first touch point; draw a line from the first point to this one.
ElseIf e.TouchDevice.Id <> firstTouchId Then
pt2.X = tp.Position.X
pt2.Y = tp.Position.Y
Dim _line As New Line()
_line.Stroke = New RadialGradientBrush(Colors.White, Colors.Black)
_line.X1 = pt1.X
_line.X2 = pt2.X
_line.Y1 = pt1.Y
_line.Y2 = pt2.Y
_line.StrokeThickness = 2
_canvas.Children.Add(_line)
End If
End If
End Sub
' Touch Up
Private Sub canvas_TouchUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.TouchEventArgs)
Dim _canvas As Canvas = CType(sender, Canvas)
If (_canvas IsNot Nothing AndAlso e.TouchDevice.Captured Is _canvas) Then
_canvas.ReleaseTouchCapture(e.TouchDevice)
End If
End Sub
End Class
Commenti
In genere si accede a tramite TouchDevice la TouchEventArgs.TouchDevice proprietà . Un TouchDevice oggetto rappresenta un singolo tocco su uno schermo. Se sono presenti più touch, usare la Id proprietà per distinguerle.
Annotazioni
Questa classe contiene una richiesta di ereditarietà a livello di classe che si applica a tutti i membri. Viene SecurityException generata un'eccezione quando la classe derivata non dispone dell'autorizzazione di attendibilità completa. Per altre informazioni sulle richieste di sicurezza, vedere Richieste di collegamento e richieste di ereditarietà.
Costruttori
| Nome | Descrizione |
|---|---|
| TouchDevice(Int32) |
Chiamato dai costruttori nelle classi derivate per inizializzare la TouchDevice classe . |
Proprietà
| Nome | Descrizione |
|---|---|
| ActiveSource |
Ottiene l'oggetto che segnala l'input PresentationSource per questo dispositivo. |
| Captured |
Ottiene l'elemento che ha acquisito l'oggetto TouchDevice. |
| CaptureMode |
Ottiene i criteri di acquisizione TouchDevicedi . |
| DirectlyOver |
Ottiene l'elemento su cui si trova direttamente il punto di contatto del tocco. |
| Dispatcher |
Ottiene l'oggetto DispatcherDispatcherObject a cui è associato. (Ereditato da DispatcherObject) |
| Id |
Ottiene l'identificatore univoco di TouchDevice, come specificato dal sistema operativo. |
| IsActive |
Ottiene un valore che indica se il dispositivo è attivo. |
| Target |
Ottiene l'elemento che riceve l'input TouchDeviceda . |
Metodi
| Nome | Descrizione |
|---|---|
| Activate() |
Aggiunge l'oggetto TouchDevice al sistema di messaggistica di input. |
| Capture(IInputElement, CaptureMode) |
Acquisisce un tocco all'elemento specificato utilizzando l'oggetto specificato CaptureMode. |
| Capture(IInputElement) |
Acquisisce un tocco all'elemento specificato usando la Element modalità di acquisizione. |
| CheckAccess() |
Determina se il thread chiamante ha accesso a questo DispatcherObjectoggetto . (Ereditato da DispatcherObject) |
| Deactivate() |
Rimuove l'oggetto TouchDevice dal sistema di messaggistica di input. |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetIntermediateTouchPoints(IInputElement) |
Quando sottoposto a override in una classe derivata, restituisce tutti i punti di tocco raccolti tra gli eventi di tocco più recenti e precedenti. |
| GetTouchPoint(IInputElement) |
Restituisce la posizione corrente del dispositivo virtuale rispetto all'elemento specificato. |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| OnCapture(IInputElement, CaptureMode) |
Chiamato quando un tocco viene acquisito in un elemento. |
| OnManipulationEnded(Boolean) |
Chiamato quando una manipolazione è terminata. |
| OnManipulationStarted() |
Chiamato all'avvio di una manipolazione. |
| ReportDown() |
Segnala che un tocco viene premuto su un elemento. |
| ReportMove() |
Segnala che un tocco viene spostato in un elemento. |
| ReportUp() |
Segnala che un tocco è stato sollevato da un elemento. |
| SetActiveSource(PresentationSource) |
Imposta l'oggetto che segnala l'input PresentationSource per questo dispositivo. |
| Synchronize() |
Forza la TouchDevice sincronizzazione dell'interfaccia utente con i punti di tocco sottostanti. |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
| VerifyAccess() |
Impone che il thread chiamante abbia accesso a questo DispatcherObjectoggetto . (Ereditato da DispatcherObject) |
Eventi
| Nome | Descrizione |
|---|---|
| Activated |
Si verifica quando TouchDevice viene aggiunto al sistema di messaggistica di input. |
| Deactivated |
Si verifica quando l'oggetto TouchDevice viene rimosso dal sistema di messaggistica di input. |
| Updated |
Si verifica quando viene inviato un messaggio di tocco. |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| IManipulator.GetPosition(IInputElement) |
Restituisce la posizione dell'oggetto IManipulator . |
| IManipulator.Id |
Ottiene l'identificatore univoco dell'oggetto TouchDevice fornito dal sistema operativo. |
| IManipulator.ManipulationEnded(Boolean) |
Si verifica al termine di una manipolazione. |