locked
changing color of ink in InkCanvas RRS feed

  • Question

  • how do I change the color of ink which already drawn on the InkCanvas?

    when I change the drawing attributes it starts to draw the new strokes with the new color but not the old ones

    Wednesday, April 6, 2011 8:53 PM

Answers

  • Hi Shreif Hassan,

    You can use InkCanvas.Stokes property to get the existing strokes. And use Stroke.DrawingAttributes to change the color.

    Here is a simple example.

        void ChangeColor(InkCanvas inkCanvas, Color color)
        {
          foreach (var stroke in inkCanvas.Strokes)
          {
            stroke.DrawingAttributes.Color = color;
          }
        }
    
    Best regards,
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Min Zhu Wednesday, April 13, 2011 2:13 AM
    Friday, April 8, 2011 2:52 AM

All replies

  • Hello Shreif,

    I'm afraid you can't access drawn Canvas items/children properties to alter them.


    Cornel Croitoriu - Senior Software Developer & Entrepreneur

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Biz-Forward.comCroitoriu.NET

    Thursday, April 7, 2011 8:04 AM
  • Hi Shreif Hassan,

    You can use InkCanvas.Stokes property to get the existing strokes. And use Stroke.DrawingAttributes to change the color.

    Here is a simple example.

        void ChangeColor(InkCanvas inkCanvas, Color color)
        {
          foreach (var stroke in inkCanvas.Strokes)
          {
            stroke.DrawingAttributes.Color = color;
          }
        }
    
    Best regards,
    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Min Zhu Wednesday, April 13, 2011 2:13 AM
    Friday, April 8, 2011 2:52 AM