Export (0) Print
Expand All

StylusPointCollection Object

Represents a collection of related StylusPoint objects.

XAML
<StylusPointCollection ...>
  oneOrMoreStylusPoints
</StylusPointCollection>
Scripting
To create an object using scripting, see CreateFromXAML.

XAML Values

oneOrMoreStylusPoints One or more StylusPoint object elements.

Remarks

This collection is used primarily by the Stroke class to keep track of the StylusPoint objects that define the appearance of the Stroke object.

A StylusPointCollection can belong to more than one Stroke object.

Collection methods such as Add or GetItem will expect or return objects that are of type StylusPoint. In addition to Collection methods, this collection also defines the method AddStylusPoints.

The XAML syntax for properties that use a StylusPoint is potentially an example of an implicit collection syntax, where you can omit an actual StylusPointCollection 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

Community Additions

Show:
© 2014 Microsoft