Export (0) Print
Expand All

StrokeCollection Object

Represents zero or more Stroke objects that are grouped together.

XAML
<StrokeCollection ...>
  oneOrMoreStrokes
</StrokeCollection>
Scripting
To create an object using scripting, see CreateFromXAML.

XAML Values

oneOrMoreStrokes One or more Stroke object elements.

Remarks

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.

Examples

JavaScript
// 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)
{
  inkPresenter.CaptureMouse();

  // 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++)
    {
      inkPresenter.Strokes.Remove(sc.GetItem(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";

    newStroke.StylusPoints.AddStylusPoints(args.GetStylusPoints(inkPresenter));
    inkPresenter.Strokes.Add(newStroke);
  }
}

// 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++)
        {
          sender.strokes.remove(hitStrokes.getItem(i));
        }
        
        // update the cached last erase point
        lastErasePoint = stylusPoints.getItem(stylusPoints.count-1);
    }

    // Ink Mode?
    if (newStroke != null)
    {
        newStroke.stylusPoints.addStylusPoints(stylusPoints);
    }
}


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

function ClearInkMouseDown(sender,args)
{
  inkPresenter.Strokes.Clear();
}

See Also

Ink Support in Microsoft Silverlight
Stroke
InkPresenter

Community Additions

Show:
© 2014 Microsoft