如何在Windows通用中更改已绘制的InkStrokes的颜色

Rob*_*ert -1 windows pen inkcanvas uwp

我在InkCanvas上画了一些墨水笔画,现在我想改变笔的颜色.我可以使用CopyDefaultDrawingAttributes和UpdateDefaultDrawingAttributes更改我绘制的任何其他笔划的颜色,并且工作正常.但是,如何更改已存在的笔画颜色StrokeContainer?我试过了:

        foreach (InkStroke stroke in inkCanvas.InkPresenter.StrokeContainer.GetStrokes())
        {
            stroke.DrawingAttributes.Color = strokeColour;
        };
Run Code Online (Sandbox Code Playgroud)

此代码执行时没有异常,但stroke.DrawingAttributes.Color仍显示以前的颜色.

有任何想法吗?

谢谢...

罗伯特

Gra*_*eng 5

您不能直接设置笔划的DrawingAttributes属性.您必须创建笔划的InkDrawingAttributes的副本,为该InkDrawingAttributes对象设置所需的值,然后将新的InkDrawingAttributes分配给笔划的DrawingAttributes.

所以你可以像这样编码:

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;
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅InkStroke.DrawingAttributes | drawingAttributes属性.