Search code examples
c#wpfgraph-drawing

Drawing a simple graph with WPF


I am looking to do some simple drawing with in a WPF application, I was wondering if this is a simple task or if I should look into some 3rd party libraries.

Quite simply I just want to draw on an image control some points and lines between those points. Is this something easy to do?

thanks!


Solution

  • for a sample to use ..you can draw a line using basics only...

    how to set canvas backgroud as image..

      ImageBrush ib = new ImageBrush();
    ib.ImageSource = new BitmapImage(new Uri(@"sampleImages\berries.jpg", UriKind.Relative));
    mycanvas.Background = ib;
    

    and you can now draw on your canvas a line like this..

    line = new Line();
    line.Stroke = Brushes.LightSteelBlue;
    line.X1 = 1;
    line.X2 = 50;
    line.Y1 = 1;
    line.Y2 = 50;
    line.StrokeThickness = 2;
    myCanvas.Children.Add(line);
    

    hope it will help you to start..