locked
Adding a line to the canvas RRS feed

  • Question

  • I don't know why this works. It should be so straightforward, so I must be overlooking something. I'm trying to create a line that crosses the canvas from C#:

    Canvas outmap = (Canvas)this.FindName("outmap");
    Line l = new Line();
    l.X1 = 0;
    l.Y1 = 0;
    l.X2 = outmap.Width;
    l.Y2 = outmap.Height;
    l.Width = 1;
    l.Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 255));
    outmap.Children.Add(l);
    outmap.Background =
    new SolidColorBrush(Color.FromRgb(255, 0, 0));

    I don't get any line on the canvas, but the backgroundcolor changes. I don't get any exceptions, and the outmap.width/height values look just fine.

    Saturday, May 19, 2007 4:57 AM

Answers

  • It should be "l.StrokeThickness = 1" instead of "l.Width=1".

     

    Saturday, May 19, 2007 11:09 AM

All replies

  • It should be "l.StrokeThickness = 1" instead of "l.Width=1".

     

    Saturday, May 19, 2007 11:09 AM
  • Duh! Thanks :-)

    Saturday, May 19, 2007 3:46 PM