RawStylusInput Class

Provides information about input from a StylusDevice to a StylusPlugIn.

Namespace:  System.Windows.Input.StylusPlugIns
Assembly:  PresentationCore (in PresentationCore.dll)

public class RawStylusInput
You cannot directly create an instance of this class in XAML.

Use the RawStylusInput to get information about the input the StylusPlugIn receives when the user moves the stylus.

The following example creates a StylusPlugIn that checks for the Down gesture. The StylusPlugIn calls NotifyWhenProcessed in OnStylusUp to subscribe to the OnStylusUpProcessed method, which is called from the application thread.

class RecognizerPlugin : StylusPlugIn
{
    GestureRecognizer recognizer;

    // StylusPointCollection that contains the stylus points of the current 
    // stroke.
    StylusPointCollection points;

    // Keeps track of the stylus to check whether two styluses are used on the 
    // digitizer. 
    int currentStylus;

    public RecognizerPlugin()
        : base()
    {
        recognizer = new GestureRecognizer();
    }

    // Collect the points as the user draws the stroke. 
    protected override void OnStylusDown(RawStylusInput rawStylusInput)
    {
        // If points is not null, there is already a stroke taking place 
        // on the digitizer, so don't create a new StylusPointsCollection. 
        if (points == null)
        {
            points = new StylusPointCollection(rawStylusInput.GetStylusPoints().Description);
            points.Add(rawStylusInput.GetStylusPoints());
            currentStylus = rawStylusInput.StylusDeviceId;
        }
    }

    // Collect the points as the user draws the stroke. 
    protected override void OnStylusMove(RawStylusInput rawStylusInput)
    {
        // Check whether the stylus that started the stroke is the same, and 
        // that the element hasn't lost focus since the stroke began. 
            if (points != null && currentStylus == rawStylusInput.StylusDeviceId)
        {
            points.Add(rawStylusInput.GetStylusPoints());
        }
    }

    // Collect the points as the user draws the stroke. 
    protected override void OnStylusUp(RawStylusInput rawStylusInput)
    {
        // Check whether the stylus that started the stroke is the same, and 
        // that the element hasn't lost focus since the stroke began. 
        if (points != null && currentStylus == rawStylusInput.StylusDeviceId)
        {
            points.Add(rawStylusInput.GetStylusPoints());

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

        points = null;
        currentStylus = 0;
    }

    // If the element loses focus, stop collecting the points and don't 
    // perform gesture recognition. 
    protected override void OnStylusLeave(RawStylusInput rawStylusInput, bool confirmed)
    {
        if (confirmed)
        {
            // Clear the StylusPointCollection
            points = null;
            currentStylus = 0;
        }
    }

    // This method 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 && recognizer.IsRecognizerAvailable)
        {
            StylusPointCollection strokePoints = callbackData as StylusPointCollection;

            if (strokePoints == null)
            {
                return;
            }

            // Create a StrokeCollection to pass to the GestureRecognizer.
            Stroke newStroke = new Stroke(strokePoints);
            StrokeCollection strokes = new StrokeCollection();
            strokes.Add(newStroke);

            ReadOnlyCollection<GestureRecognitionResult> results = recognizer.Recognize(strokes);

            // If the GestureRecognizer recognizes the stroke as a Down 
            // gesture with strong confidence, raise an event. 
            if (results[0].ApplicationGesture == ApplicationGesture.Down &&
                results[0].RecognitionConfidence == RecognitionConfidence.Strong)
            {
                //raise event
            }
        }
    }
}

System.Object
  System.Windows.Input.StylusPlugIns.RawStylusInput

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft