StrokeCollection Object

Represents zero or more Stroke objects that are grouped together.

<StrokeCollection ...>
To create an object using scripting, see CreateFromXAML.

XAML Values

oneOrMoreStrokes One or more Stroke object elements.


Count, Name


Add, Clear, Equals, FindName, GetBounds, GetHost, GetItem, GetValue, HitTest, Insert, Remove, RemoveAt, SetValue


StrokeCollection is used by the Strokes property object to store Stroke information.

Collection methods such as Add or GetItem will expect or return objects that are of type Stroke. In addition to Collection methods, this collection also defines the methods GetBounds and HitTest.

The XAML syntax for properties that use a StrokeCollection is potentially an example of an implicit collection syntax, where you can omit an actual StrokeCollection object element. However, prepopulating an InkPresenter with strokes is not a common technique; usually you start with a blank Strokes collection and capture strokes as user input with runtime JavaScript. For more information about XAML implicit collection syntax, see XAML Syntax Overview.


// Inking variables
var agCtrl;
var inkPresenter; // Corresponds to InkPresenter element in XAML
var newStroke = null; // The Stroke variable we'll use here in mouse handlers
function root_Loaded(sender, args)
  // Get the html object which contains the Silverlight plug-in.
  agCtrl = sender.GetHost();
  // hold on to the InkPresenter plug-in interface
  inkPresenter = sender.findname("inkPresenterElement");
// Capture mouse and create the stroke
function InkPresenterMouseDown(sender,args)
  // Erase mode?
  if (args.GetStylusInfo().IsInverted)
    var sc = agCtrl.content.createFromXaml("<StrokeCollection/>");
    sc = inkPresenter.Strokes.HitTest(args.GetStylusPoints(inkPresenter));
    for (var i = 0; i < sc.Count; i++)
  else // Ink mode
    newStroke = agCtrl.content.createFromXaml('<Stroke/>');
    var da = agCtrl.content.createFromXaml('<DrawingAttributes/>');
    newStroke.DrawingAttributes = da;
    var spc = agCtrl.content.createFromXaml('<StylusPointCollection/>');
    newStroke.StylusPoints = spc;
    newStroke.DrawingAttributes.Width = 5;
    newStroke.DrawingAttributes.Height = 5;
    newStroke.DrawingAttributes.Color = "Green";
    newStroke.DrawingAttributes.OutlineColor = "Black";
// Add the new points to the Stroke we're working with
// or delete strokes if we are in erase mode
function inkPresenterMouseMove(sender, args)
    var stylusPoints = args.getStylusPoints(sender);
    // Erase Mode?
    if (lastErasePoint != null)
        // connect the point from previous mouse event
        // to the current collection of stylus points
        stylusPoints.insert(0, lastErasePoint);
        var hitStrokes = sender.strokes.hitTest(stylusPoints);
        // Remove the strokes that were intersected above
        for (var i = 0; i < hitStrokes.Count; i++)
        // update the cached last erase point
        lastErasePoint = stylusPoints.getItem(stylusPoints.count-1);
    // Ink Mode?
    if (newStroke != null)
// Release the mouse
function InkPresenterMouseUp(sender,args)
  newStroke = null;
function ClearInkMouseDown(sender,args)

See Also

Ink Support in Microsoft Silverlight