How do you draw a line on a canvas in WPF that is 1 pixel thick?

csharp , wpf , line , visual studio 2010 United States
  • 10 years ago

    How do you draw a line on a canvas in WPF that is 1 pixel thick?

    This is the method I am using for drawing a line on a canvas in WPF that uses the line class set to 1 pixel thick but it actually draws a line that is two pixels thick:

    [code] Line myLine = new Line();

            myLine.Stroke = System.Windows.Media.Brushes.Black;
            myLine.X1 = 100;
            myLine.X2 = 140;  
            myLine.Y1 = 200;
            myLine.Y2 = 200;
            myLine.StrokeThickness = 1;


    Microsoft might have decided to set a standard for line thickness and the minimum is 2 pixels thick when you set the strockThickness to 1, but when you already have rectangles drawn in XAML and even error fonts using WingDings, it is an obvious miss-match. How do you draw a line that is truly 1 pixel thick?

    I tried: myLine.StrokeThickness = 0.5; but that only makes the line burry.

    Is there some sort of setting I need to make in the grid instead?

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programs must be written for people to read, and only incidentally for machines to execute.”