2016-07-05 119 views
-1

我在InkCanvas上绘制了一些墨迹笔画,现在想要更改笔的颜色。我可以改变使用CopyDefaultDrawingAttributes和UpdateDefaultDrawingAttributes绘制的任何额外笔画的颜色,并且工作正常。但是,如何改变已经存在的笔画的颜色StrokeContainer?我试过了:如何更改已在Windows中绘制InkStrokes的颜色通用

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

此代码执行时没有例外,但stroke.DrawingAttributes.Color仍然显示以前的颜色。

任何想法?

谢谢...

罗伯特

+0

是否尝试更新DrawingAttributes属性,如[此处的示例]所示(https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.input.inking.inkdrawingattributes .color.aspx)? – Clemens

回答

4

不能直接设置笔触的财产的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 | drawingAttributes property

+0

谢谢格雷斯 - 工作。 – Robert

+0

@罗伯特,太棒了,你的问题是否被接受? :) –

相关问题