Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Same line drawn different?
    primarykey
    data
    text
    <p>I have a canvas and in it I'm drawing some lines:</p> <pre><code>for (int i = 1; i &gt;= 100; i++) { // Line LineGeometry line = new LineGeometry(); line.StartPoint = new Point(i * 100, 0); line.EndPoint = new Point(i * 100, 100 * 100); // Path Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 1; // Add to canvas myPath.Data = line; canvas1.Children.Add(myPath); } </code></pre> <p>Well, nothing special, but it makes problems - the lines are drawn different! The canvas is inside a scrollviewer, the following image shows different positions of the canvas, however the lines <em>should</em> look the same? Hell, how is this possible? The code above is the only code I've written by hand and it's the only content in the canvas. Anyone knows why this happens and how to prevent this? Thank you very much! Screenshot: <a href="http://www.imagebanana.com/view/c01nrd6i/lines.png" rel="nofollow noreferrer">http://www.imagebanana.com/view/c01nrd6i/lines.png</a> </p> <p><strong>Update</strong></p> <p>So maurizios solution works fine, but only as long as you use the LineGeometry to position the line, I still get blurry lines when I use the canvas to position the line. Anyone can please help me with this? Thank you very much!</p> <p>Sample screenshot and the code for it:</p> <p>Screenshot: <a href="http://www.imagebanana.com/view/lu7z3mcv/canvasposprob.png" rel="nofollow noreferrer">http://www.imagebanana.com/view/lu7z3mcv/canvasposprob.png</a></p> <p>Code:</p> <pre><code>// LINE POSITIONED BY CANVAS -&gt; LINE GETS BLURRY // Line LineGeometry line = new LineGeometry(); line.StartPoint = new Point(0, 0); line.EndPoint = new Point(0, 100); // Path Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 5; myPath.SnapsToDevicePixels = true; line.Freeze(); // Add to canvas myPath.Data = line; Canvas.SetLeft(myPath, 10); // LINE POSITIONED BY CANVAS: x=10 Canvas.SetTop(myPath, 0); // LINE POSITIONED BY CANVAS canvas1.SnapsToDevicePixels = true; // doesnt help canvas1.Children.Add(myPath); // LINE POSITIONED BY LINE GEOMETRY // Line LineGeometry line2 = new LineGeometry(); line2.StartPoint = new Point(20, 0); //LINE POSITIONED BY LINE GEOMETRY: x=20 line2.EndPoint = new Point(20, 100); // Path Path myPath2 = new Path(); myPath2.Stroke = Brushes.Blue; myPath2.StrokeThickness = 5; myPath2.SnapsToDevicePixels = true; line2.Freeze(); // Add to canvas myPath2.Data = line2; // Don't use the canvas for positioning //Canvas.SetTop(myPath, 10); //NEW //Canvas.SetLeft(myPath, 10); //NEW canvas1.Children.Add(myPath2); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload