0

我在 InkCanvas 上绘制了一些墨水笔画,现在想更改笔的颜色。我可以更改使用 CopyDefaultDrawingAttributes 和 UpdateDefaultDrawingAttributes 绘制的任何其他笔划的颜色,并且效果很好。但是如何更改已经存在的 StrokeContainer 笔划的颜色?我试过了:

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

此代码毫无例外地执行,但 stroke.DrawingAttributes.Color 仍显示以前的颜色。

有任何想法吗?

谢谢...

罗伯特

4

1 回答 1

6

不能直接设置笔画的 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;
}

更多信息,可以参考InkStroke.DrawingAttributes | 绘图属性属性

于 2016-07-05T09:31:38.450 回答