0

So I have an InkCanvas to which I have added "custom strokes".

I am at a complete loss as to how to erase custom strokes added to the InkCanvas through its DrawingContext. (Google has been of no help:( ) Making the assumption that I have a bounding rectangle for the area on the InkCanvas I want to erase, how can this be done?

(I am quickly coming to the conclusion that once something is drawn on the DrawingContext it can not be removed -- only convered :( ).

The Custom Strokes are created in the standard way by overriding the DrawCore method of the Stroke, e.g.,

// Draw Rectangle
public class RectangleStroke : Stroke
{
    // Constructor
    public RectangleStroke(StylusPointCollection pts)
        : base(pts)
    {
        StylusPoints = pts;
    }

    protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
    {
        if (drawingContext == null)
        {
            throw new ArgumentNullException("drawingContext");
        }
        if (null == drawingAttributes)
        {
            throw new ArgumentNullException("drawingAttributes");
        }
        DrawingAttributes originalDa = drawingAttributes.Clone();
        SolidColorBrush brush = new SolidColorBrush(drawingAttributes.Color);
        brush.Freeze();
        Pen pen = new Pen(brush, 1);

        StylusPoint stp = StylusPoints[0];
        StylusPoint sp = StylusPoints[1];

        drawingContext.DrawRectangle(brush, pen, new Rect(new Point(sp.X, sp.Y), new Point(stp.X, stp.Y)));
    }

}

Similar methods results in a picture like: enter image description here

How are custom strokes erased knowing only the bounding rectangle?

Thanks for any help or suggestions.

Alan Wayne
  • 5,122
  • 10
  • 52
  • 95

1 Answers1

1

Ugh...What should have been obvious is that the custom strokes inherit from Stroke and even though a datacontext once written can not be unwritten, the InkCanvas can erase its strokes--including custom strokes--by changing the InkCanvasEditingMode to EraseByStroke. Hope this helps somebody.

Alan Wayne
  • 5,122
  • 10
  • 52
  • 95