[SOLVED] wpf how do I ensure that a line i draw isn't aliased away?

Issue

Correct me if I’m wrong, but I believe that if I draw a line in WPF and it is small enough, then the line will be aliased out. Also if a line is not drawn on a pixel then it may become dimmer. I assume that if a line is < 1 pixel wide it will also be dimmed by averaging the colors that are in that spot.

My goal is to draw a graph of a bunch of signals without having the lines I draw disappear or become dimmed to the point the user might not notice them.

Questions: if I draw a line with a width of 1 device independent pixels, is it guaranteed to be at least one pixel wide? if not, is there any way to ensure that a line is at least one pixel wide?

Solution

You have to speficy

SnapsToDevicePixels=”True”

in the header of your XAML

ex:

   <Window
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       SnapsToDevicePixels="True">

You can see the way it changes the line in this link

Answered By – Pic Mickael

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *