StylusPlugIn Klasse

Definition

Stellt ein Plug-In dar, das der Eigenschaft eines Steuerelements StylusPlugIns hinzugefügt werden kann.

public ref class StylusPlugIn abstract
public abstract class StylusPlugIn
type StylusPlugIn = class
Public MustInherit Class StylusPlugIn
Vererbung
StylusPlugIn
Abgeleitet

Beispiele

Im folgenden Beispiel wird eine Benutzerdefinierte StylusPlugIn erstellt, die die Freihandeingabe auf einen bestimmten Bereich des Steuerelements einschränkt.

// EventArgs for the StrokeRendered event.
public class StrokeRenderedEventArgs : EventArgs
{
    StylusPointCollection strokePoints;

    public StrokeRenderedEventArgs(StylusPointCollection points)
    {
        strokePoints = points;
    }

    public StylusPointCollection StrokePoints
    {
        get
        {
            return strokePoints;
        }
    }
}

// EventHandler for the StrokeRendered event.
public delegate void StrokeRenderedEventHandler(object sender, StrokeRenderedEventArgs e);

// A StylusPlugin that restricts the input area
class FilterPlugin : StylusPlugIn
{
    StylusPointCollection collectedPoints;
    int currentStylus = -1;
    public event StrokeRenderedEventHandler StrokeRendered;

    protected override void OnStylusDown(RawStylusInput rawStylusInput)
    {
        // Run the base class before modifying the data
        base.OnStylusDown(rawStylusInput);

        if (currentStylus == -1)
        {
            StylusPointCollection pointsFromEvent = rawStylusInput.GetStylusPoints();

            // Create an emtpy StylusPointCollection to contain the filtered
            // points.
            collectedPoints = new StylusPointCollection(pointsFromEvent.Description);
            
            // Restrict the stylus input and add the filtered 
            // points to collectedPoints. 
            StylusPointCollection points = FilterPackets(pointsFromEvent);
            rawStylusInput.SetStylusPoints(points);
            collectedPoints.Add(points);

            currentStylus = rawStylusInput.StylusDeviceId;
        }
    }

    protected override void OnStylusMove(RawStylusInput rawStylusInput)
    {
        // Run the base class before modifying the data
        base.OnStylusMove(rawStylusInput);

        if (currentStylus == rawStylusInput.StylusDeviceId)
        {
            StylusPointCollection pointsFromEvent = rawStylusInput.GetStylusPoints();

            // Restrict the stylus input and add the filtered 
            // points to collectedPoints. 
            StylusPointCollection points = FilterPackets(pointsFromEvent);
            rawStylusInput.SetStylusPoints(points);
            collectedPoints.Add(points);
        }
    }

    protected override void OnStylusUp(RawStylusInput rawStylusInput)
    {
        // Run the base class before modifying the data
        base.OnStylusUp(rawStylusInput);

        if (currentStylus == rawStylusInput.StylusDeviceId)
        {
            StylusPointCollection pointsFromEvent = rawStylusInput.GetStylusPoints();

            // Restrict the stylus input and add the filtered 
            // points to collectedPoints. 
            StylusPointCollection points = FilterPackets(pointsFromEvent);
            rawStylusInput.SetStylusPoints(points);
            collectedPoints.Add(points);

            // Subscribe to the OnStylusUpProcessed method.
            rawStylusInput.NotifyWhenProcessed(collectedPoints);

            currentStylus = -1;
        }
    }

    private StylusPointCollection FilterPackets(StylusPointCollection stylusPoints)
    {
        // Modify the (X,Y) data to move the points 
        // inside the acceptable input area, if necessary
        for (int i = 0; i < stylusPoints.Count; i++)
        {
            StylusPoint sp = stylusPoints[i];
            if (sp.X < 50) sp.X = 50;
            if (sp.X > 250) sp.X = 250;
            if (sp.Y < 50) sp.Y = 50;
            if (sp.Y > 250) sp.Y = 250;
            stylusPoints[i] = sp;
        }

        // Return the modified StylusPoints.
        return stylusPoints;
    }

    // This is called on the application thread.  
    protected override void OnStylusUpProcessed(object callbackData, bool targetVerified)
    {
        // Check that the element actually receive the OnStylusUp input.
        if (targetVerified)
        {
            StylusPointCollection strokePoints = callbackData as StylusPointCollection;

            if (strokePoints == null)
            {
                return;
            }

            // Raise the StrokeRendered event so the consumer of the plugin can
            // add the filtered stroke to its StrokeCollection.
            StrokeRenderedEventArgs e = new StrokeRenderedEventArgs(strokePoints);
            OnStrokeRendered(e);
        }
    }

    protected virtual void OnStrokeRendered(StrokeRenderedEventArgs e)
    {
        if (StrokeRendered != null)
        {
            StrokeRendered(this, e);
        }
    }
}
' EventArgs for the StrokeRendered event.
Public Class StrokeRenderedEventArgs
    Inherits EventArgs

    Private currentStrokePoints As StylusPointCollection

    Public Sub New(ByVal points As StylusPointCollection)

        currentStrokePoints = points

    End Sub


    Public ReadOnly Property StrokePoints() As StylusPointCollection
        Get
            Return currentStrokePoints
        End Get
    End Property
End Class

' EventHandler for the StrokeRendered event.
Public Delegate Sub StrokeRenderedEventHandler(ByVal sender As Object, ByVal e As StrokeRenderedEventArgs) 


' A StylusPlugin that restricts the input area
Class FilterPlugin
    Inherits StylusPlugIn

    Private collectedPoints As StylusPointCollection
    Private currentStylus As Integer = -1
    Public Event StrokeRendered As StrokeRenderedEventHandler


    Protected Overrides Sub OnStylusDown(ByVal rawStylusInput As RawStylusInput)

        ' Run the base class before we modify the data
        MyBase.OnStylusDown(rawStylusInput)

        If currentStylus = -1 Then

            Dim pointsFromEvent As StylusPointCollection = rawStylusInput.GetStylusPoints()

            ' Create an emtpy StylusPointCollection to contain the filtered
            ' points.
            collectedPoints = New StylusPointCollection(pointsFromEvent.Description)

            ' Restrict the stylus input and add the filtered 
            ' points to collectedPoints. 
            Dim points As StylusPointCollection = FilterPackets(pointsFromEvent)
            rawStylusInput.SetStylusPoints(points)
            collectedPoints.Add(points)

            currentStylus = rawStylusInput.StylusDeviceId

        End If

    End Sub


    Protected Overrides Sub OnStylusMove(ByVal rawStylusInput As RawStylusInput)

        ' Run the base class before we modify the data
        MyBase.OnStylusMove(rawStylusInput)

        If currentStylus = rawStylusInput.StylusDeviceId Then

            Dim pointsFromEvent As StylusPointCollection = rawStylusInput.GetStylusPoints()

            ' Restrict the stylus input and add the filtered 
            ' points to collectedPoints. 
            Dim points As StylusPointCollection = FilterPackets(pointsFromEvent)
            rawStylusInput.SetStylusPoints(points)
            collectedPoints.Add(points)

        End If

    End Sub

    Protected Overrides Sub OnStylusUp(ByVal rawStylusInput As RawStylusInput)

        ' Run the base class before we modify the data
        MyBase.OnStylusUp(rawStylusInput)

        If currentStylus = rawStylusInput.StylusDeviceId Then

            Dim pointsFromEvent As StylusPointCollection = rawStylusInput.GetStylusPoints()

            ' Restrict the stylus input and add the filtered 
            ' points to collectedPoints. 
            Dim points As StylusPointCollection = FilterPackets(pointsFromEvent)
            rawStylusInput.SetStylusPoints(points)
            collectedPoints.Add(points)

            RecordPoints(collectedPoints, "collectPoints - StylusUp")
            ' Subscribe to the OnStylusUpProcessed method.
            rawStylusInput.NotifyWhenProcessed(collectedPoints)

            currentStylus = -1

        End If

    End Sub


    Private Function FilterPackets(ByVal stylusPoints As StylusPointCollection) As StylusPointCollection

        ' Modify the (X,Y) data to move the points 
        ' inside the acceptable input area, if necessary.
        Dim i As Integer

        For i = 0 To stylusPoints.Count - 1

            Dim sp As StylusPoint = stylusPoints(i)

            If sp.X < 50 Then
                sp.X = 50
            End If

            If sp.X > 250 Then
                sp.X = 250
            End If

            If sp.Y < 50 Then
                sp.Y = 50
            End If

            If sp.Y > 250 Then
                sp.Y = 250
            End If

            stylusPoints(i) = sp

        Next i

        ' Return the modified StylusPoints.
        Return stylusPoints

    End Function 'FilterPackets

    ' This is called on the application thread.
    Protected Overrides Sub OnStylusUpProcessed(ByVal callbackData As Object, _
                                                ByVal targetVerified As Boolean)

        ' Check that the element actually receive the OnStylusUp input.
        If targetVerified Then
            Dim strokePoints As StylusPointCollection

            strokePoints = CType(callbackData, StylusPointCollection)

            If strokePoints Is Nothing Then
                Return
            End If

            ' Raise the StrokeRendered event so the consumer of the plugin can
            ' add the filtered stroke to its StrokeCollection.
            RecordPoints(strokePoints, "onStylusUpProcessed")
            Dim e As New StrokeRenderedEventArgs(strokePoints)
            OnStrokeRendered(e)
        End If

    End Sub


    Protected Overridable Sub OnStrokeRendered(ByVal e As StrokeRenderedEventArgs)

        RaiseEvent StrokeRendered(Me, e)

    End Sub

    Public Sub RecordPoints(ByVal points As StylusPointCollection, ByVal name As String)

        System.Diagnostics.Debug.WriteLine(name)
        For Each point As StylusPoint In points
            System.Diagnostics.Debug.WriteLine("   x: " & point.X & " y: " & point.Y)
        Next
    End Sub
End Class

Hinweise

Auf diese StylusPlugIn Weise können Sie Objekte in separaten Threads bearbeiten StylusPoint . Separate Threads werden verwendet, sodass die Freihandeingaben weiterhin als Tablet-Stift-Eingabedaten gerendert werden, auch wenn die Anwendung etwas anderes ausführt.

Um Eingabestiftpunkte von der Hardware abzufangen, erstellen Sie eine Klasse, die von der StylusPlugIn Klasse erbt. Die StylusPlugIn Klasse verfügt über die folgenden Methoden, mit denen Sie Objekte in einem Thread im Stiftthreadpool überschreiben StylusPoint können.

Die Eingabe des Stifts wird an das Element StylusPlugIn im Stiftthread weitergeleitet. Da genaue Treffertests nicht für den Stiftthread ausgeführt werden können, erhalten einige Elemente gelegentlich Eingabestifteingaben, die für andere Elemente vorgesehen sind. Wenn Sie sicherstellen müssen, dass die Eingabe ordnungsgemäß weitergeleitet wurde, bevor Sie einen Vorgang ausführen, abonnieren Sie den Vorgang in der OnStylusDownProcessed-, OnStylusMoveProcessed- oder OnStylusUpProcessed-Methode, und führen Sie ihn dort aus. Diese Methoden werden vom Hauptanwendungsthread aufgerufen, nachdem genaue Treffertests durchgeführt wurden. Um diese Methoden zu abonnieren, rufen Sie die NotifyWhenProcessed-Methode in der Methode auf, die im Stiftthread auftritt. Wenn Sie sich beispielsweise einwähnen NotifyWhenProcessedOnStylusMove, tritt dies OnStylusMoveProcessed auf.

Note

Wenn Sie ein StylusPlugIn Steuerelement verwenden, sollten Sie das Plug-In und die Steuerung umfassend testen, um sicherzustellen, dass sie keine unbeabsichtigten Ausnahmen auslösen.

XAML-Textverwendung

Diese Klasse wird in der Regel nicht in XAML verwendet.

Konstruktoren

Name Beschreibung
StylusPlugIn()

Initialisiert eine neue Instanz der StylusPlugIn-Klasse.

Eigenschaften

Name Beschreibung
Element

Ruft ab UIElement , an den die StylusPlugIn angefügte Datei angefügt ist.

ElementBounds

Ruft die zwischengespeicherten Grenzen des Elements ab.

Enabled

Ruft ab oder legt fest, ob die StylusPlugIn Aktiv ist.

IsActiveForInput

Ruft ab, ob die StylusPlugIn Eingabe akzeptiert werden kann.

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
OnAdded()

Tritt auf, wenn das StylusPlugIn Element einem Element hinzugefügt wird.

OnEnabledChanged()

Tritt auf, wenn sich die Enabled Eigenschaft ändert.

OnIsActiveForInputChanged()

Tritt auf, wenn sich die IsActiveForInput Eigenschaft ändert.

OnRemoved()

Tritt auf, wenn das StylusPlugIn Element aus einem Element entfernt wird.

OnStylusDown(RawStylusInput)

Tritt auf einem Thread im Stiftthreadpool auf, wenn der Tabletstift den Digitalisierungsgerät berührt.

OnStylusDownProcessed(Object, Boolean)

Tritt auf dem Ui-Thread der Anwendung (Benutzeroberfläche) auf, wenn der Tabletstift den Digitalisierungsgerät berührt.

OnStylusEnter(RawStylusInput, Boolean)

Tritt auf einem Stiftthread auf, wenn der Cursor die Grenzen eines Elements eingibt.

OnStylusLeave(RawStylusInput, Boolean)

Tritt auf einem Stiftthread auf, wenn der Cursor die Grenzen eines Elements verlässt.

OnStylusMove(RawStylusInput)

Tritt auf einem Stiftthread auf, wenn der Tablet-Stift auf dem Digitalisierungsgerät bewegt wird.

OnStylusMoveProcessed(Object, Boolean)

Tritt auf dem Ui-Thread der Anwendung (Benutzeroberfläche) auf, wenn der Tablet-Stift auf dem Digitalisierungsgerät bewegt wird.

OnStylusUp(RawStylusInput)

Tritt auf einem Stiftthread auf, wenn der Benutzer den Tabletstift vom Digitalisierungsgerät aufhebt.

OnStylusUpProcessed(Object, Boolean)

Tritt auf dem Ui-Thread der Anwendung (Benutzeroberfläche) auf, wenn der Benutzer den Tablet-Stift vom Digitalisierungsgerät aufhebt.

ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Gilt für: