You may have noticed that things can get slightly blurry in WPF rendering with 1 pixel thick strokes clearly spanning more than one pixel. That's because WPF works at infinite resolution (well, as infinite as the double
type will allow).
For example, here is a Rectangle positioned on a canvas at 20, 20.
Now look what happens if we move the rectangle down and to the right by just half a 'pixel', placing it at 20.5, 20.5.
Notice how the horizontal and vertical lines are blurred. This is how that half 'pixel' is represented - by partially occupying the two pixels that the line lies between.
Sometimes this isn't the effect we want and would prefer to stick with a nice crisp line. As usual, the WPF guys catered for us via UIElement's SnapsToDevicePixels
<Rectangle Canvas.Top="20.5" Canvas.Left="20.5" Width="10" Height="10" Stroke="Black" SnapsToDevicePixels="true" />
Neat. Best of all, this doesn't disable anti-aliasing. The SnapsToDevicePixels only applies to horizontal and vertical lines, as demonstrated by these two rectangles with rounded corners. The right one has SnapsToDevicePixels set to True.
24 Jul 2007
» Next Post:
« Previous Post:
Sortable ListView in WPF
Comments are closed for this post.