locked
How to draw dash-dot line in Inkcanvas with ink? RRS feed

  • Question

  • ı want to draw dashed line using stylus point with mouse drag but how?
    Friday, June 17, 2011 2:26 PM

Answers

  • Hi mymustafayilmaz,

    I think you could refer to below code snippet:

    StylusPointCollection spc1 = new StylusPointCollection();

    AddDash(spc1, 0);

    StylusPointCollection spc2 = new StylusPointCollection();

    AddDot(spc2, 15);

    StylusPointCollection spc3 = new StylusPointCollection();

    AddDash(spc3, 20);

     

    this.inkCanvas1.Strokes.Add(new Stroke(spc1));

    this.inkCanvas1.Strokes.Add(new Stroke(spc2));

    this.inkCanvas1.Strokes.Add(new Stroke(spc3));

    private static void AddDash(StylusPointCollection spc, double start)

    {

        for (double i = start; i < (start + 10); i += 0.01)

        {

            spc.Add(new StylusPoint(i, 10));

        }

    }

     

    private static void AddDot(StylusPointCollection spc, double start)

    {

        for (double i = start; i < (start + 2); i += 0.01)

        {

            spc.Add(new StylusPoint(i, 10));

     

        }

    }

     

    Best regards,


    Sheldon _Xiao[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.

    • Proposed as answer by Sheldon _Xiao Monday, June 27, 2011 8:13 AM
    • Marked as answer by Sheldon _Xiao Monday, July 4, 2011 4:01 AM
    Monday, June 20, 2011 8:09 AM

All replies

  • You use the strokedasharray property to do the dash dotting.

    Maybe you want to take a look at this thread for drawing generally.

    http://social.msdn.microsoft.com/Forums/en-NZ/wpf/thread/bdf20a04-b550-473d-aa68-96fbbb314de4

    Friday, June 17, 2011 2:45 PM
  • Thanks,but ı must use stylus point.because ı want to add stroke and ınkcanvas
    Saturday, June 18, 2011 7:02 AM
  • Hi mymustafayilmaz,

    I think you could refer to below code snippet:

    StylusPointCollection spc1 = new StylusPointCollection();

    AddDash(spc1, 0);

    StylusPointCollection spc2 = new StylusPointCollection();

    AddDot(spc2, 15);

    StylusPointCollection spc3 = new StylusPointCollection();

    AddDash(spc3, 20);

     

    this.inkCanvas1.Strokes.Add(new Stroke(spc1));

    this.inkCanvas1.Strokes.Add(new Stroke(spc2));

    this.inkCanvas1.Strokes.Add(new Stroke(spc3));

    private static void AddDash(StylusPointCollection spc, double start)

    {

        for (double i = start; i < (start + 10); i += 0.01)

        {

            spc.Add(new StylusPoint(i, 10));

        }

    }

     

    private static void AddDot(StylusPointCollection spc, double start)

    {

        for (double i = start; i < (start + 2); i += 0.01)

        {

            spc.Add(new StylusPoint(i, 10));

     

        }

    }

     

    Best regards,


    Sheldon _Xiao[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.

    • Proposed as answer by Sheldon _Xiao Monday, June 27, 2011 8:13 AM
    • Marked as answer by Sheldon _Xiao Monday, July 4, 2011 4:01 AM
    Monday, June 20, 2011 8:09 AM
  • hello sheldon,

    seems its not possible to draw that dashed line via mouse move event.. it appears as dashed line but if you want to  use x,y properties of mouse its going crazy :) Isnt it possible to draw dashed line via mouse on inkcanvas

    Monday, June 20, 2011 10:45 AM
  • Hi GokhanGok,

    I have not come up a way to achieve your goal, why you need this behavior?

     

    Best regards,


    Sheldon _Xiao[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.

    Monday, June 27, 2011 8:13 AM