0

I have drawn some ink strokes on an InkCanvas and am now wanting to change the pen colour. I can change the colour of any additional strokes I draw using CopyDefaultDrawingAttributes and UpdateDefaultDrawingAttributes and that works fine. But how do I alter the color of the strokes that are already present StrokeContainer? I've tried:

        foreach (InkStroke stroke in inkCanvas.InkPresenter.StrokeContainer.GetStrokes())
        {
            stroke.DrawingAttributes.Color = strokeColour;
        };

This code executes with no exceptions, but stroke.DrawingAttributes.Color still shows the previous colour.

Any ideas?

Thanks...

Robert

Robert
  • 231
  • 3
  • 10
  • Did you try to update the DrawingAttributes property, as shown in [the example here](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.inking.inkdrawingattributes.color.aspx)? – Clemens Jul 05 '16 at 07:55

1 Answers1

6

You cannot set the DrawingAttributes property of the stroke directly. You must create a copy of the InkDrawingAttributes of the stroke, set the desired values for that InkDrawingAttributes object, and then assign the new InkDrawingAttributes to the DrawingAttributes of the stroke.

So you can code for example like this:

foreach (InkStroke stroke in inkCanvas.InkPresenter.StrokeContainer.GetStrokes())
{
    //stroke.DrawingAttributes.Color = Windows.UI.Colors.Yellow;
    InkDrawingAttributes drawingAttributes = new InkDrawingAttributes();
    drawingAttributes.Color = Windows.UI.Colors.Yellow;
    stroke.DrawingAttributes = drawingAttributes;
}

For more information, you can refer to InkStroke.DrawingAttributes | drawingAttributes property.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45