Partager via


StylusPoints

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the collection of StylusPoint objects that make up a Stroke.

<object ...>
  <object.StylusPoints>
    oneOrMoreStylusPoints
  <object.StylusPoints/>
<object/>
value = object.StylusPoints
object.StylusPoints = value

XAML Values

Value

Description

oneOrMoreStylusPoints

One or more StylusPoint object elements.

Property Value

Type: StylusPointCollection

The collection of StylusPoint objects that make up the Stroke.

This property is read/write.

Managed Equivalent

StylusPoints

Remarks

Setting StylusPoints in XAML is not a typical scenario, but it is possible. (Usually, you use this property to capture user input instead of prepopulating strokes.) You could use this technique to place watermarks or guides on the ink canvas as actual strokes.

The XAML syntax for properties that use a StylusPointCollection is an example of an implicit collection syntax, where you can omit the StylusPointCollection object element. The <DoubleAnimationUsingKeyFrames.Strokes> property element is required for this collection syntax; StylusPoints is not the default collection property of a Stroke. You would include one or more StylusPoint object elements as child elements of the DoubleAnimationUsingKeyFrames.Strokes property element.

Example

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, and 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, use the default stroke height and width.
   else
   {
     daWidth = 3;
     daHeight = 3;
   }
   
   // Set the drawing attribute 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;
}

Applies To

Stroke