Search code examples
wpfxamlinkcanvas

How to use ink canvas using predifined x, y values?


I have some set of x,y values,I want to bind them to my xamal and while executing the application it needs to draw the stroke automatically without any input from the user. Is that possible with ink canvas or do i need to use any other control?


Solution

  • You can add strokes in code, like I do in the loaded event:

    <InkCanvas Loaded="InkCanvas_Loaded"/>
    

    Code:

    private void InkCanvas_Loaded(object sender, RoutedEventArgs e)
    {
        var s = sender as InkCanvas;
        s.Strokes.Add(new System.Windows.Ink.Stroke(new StylusPointCollection(new Point[]
        {
            new Point(10, 10),
            new Point(100, 10),
            new Point(100, 100),
            new Point(10, 100),
            new Point(10, 10),
        })));
    }