Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

StylusInfo Object

Represents information about the state of the stylus.

XAML
Cannot be used in XAML.
Scripting
To create an object using scripting, see CreateFromXAML.

Remarks

For mouse input that is used for ink support in leiu of a stylus, DeviceType returns Mouse.

Examples

The following example uses the PressureFactor property to determine the size of a stroke. The PressureFactor is obtained from the first StylusPoint of each stroke, then the stroke Width and Height is calculated by multiplying the PressureFactor by 20.

JavaScript
var agCtrl;
var inkPresenter; // Corresponds to InkPresenter element in xaml
var newStroke = null; // The Stroke variable we'll use here in mouse handlers
var daWidth;
var daHeight;

function root_Loaded(sender, args) 
{
    // Get the html object which contains the Silverlight plug-in
    agCtrl = sender.GetHost();
    inkPresenter = sender.findname("inkPresenterElement");
}

// Capture mouse movement when the left button is pressed then create the stroke.
function InkPresenterMouseDown(sender,args)
{
   inkPresenter.CaptureMouse();
   newStroke = agCtrl.content.createFromXaml('<Stroke/>');
   
   // Get the DeviceType
   if(args.GetStylusInfo().deviceType == "Stylus")
   {
     var sps = args.GetStylusPoints(inkPresenter);
     SetStylusStrokeSize(sps);
   }
   // If the device type is not a stylus then use the default stroke height and width.
   else
   {
     daWidth = 3;
     daHeight = 3;
   }
   
   // Set the drawing attributes properties
   newStroke.DrawingAttributes.Width = daWidth;
   newStroke.DrawingAttributes.Height = daHeight;
   newStroke.DrawingAttributes.Color = "Blue";
   newStroke.DrawingAttributes.OutlineColor = "Orange";
   
   newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter));
   inkPresenter.Strokes.Add(newStroke);
}

// Add the new points to the Stroke we're working with
function InkPresenterMouseMove(sender,args)
{
   if (newStroke != null)
   {
      newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter));
   }
}

// Release the mouse
function InkPresenterMouseUp(sender,args)
{
   newStroke = null;
}

// Set the size of the stroke based on the initial pressureFactor of the stroke.
function SetStylusStrokeSize(sps)
{
    var p;
    // Set variable p to the first StylusPoint in the Stroke
    p = sps.getItem(0).pressureFactor;
    daWidth = p * 20.0;
    daHeight = p * 20.0;
}

See Also

Ink Support In Microsoft Silverlight
MouseEventArgs

Community Additions

Show:
© 2015 Microsoft