19

I draw a rectangle using:

<Rectangle Width="300" Height="100" Stroke="Blue" StrokeThickness="6"> </Rectangle>

but there is anti-aliasing applied to it. Is there a way to turn this off? I want it to be sharp and clear.

Joan Venge
  • 315,713
  • 212
  • 479
  • 689

3 Answers3

25

A little late but RenderOptions.EdgeMode="Aliased" does the trick

<Rectangle Width="300"
           Height="100"
           Stroke="Blue"
           StrokeThickness="6"
           RenderOptions.EdgeMode="Aliased"/>
Fredrik Hedblad
  • 83,499
  • 23
  • 264
  • 266
  • 2
    I have noticed significant performance degradation with this method. Perhaps it is driver bound but I have a suspicion that it falls back to software. – Gusdor Jan 23 '13 at 15:40
5

Check out SnapToDevicePixels: http://msdn.microsoft.com/en-us/library/aa970908.aspx

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • 3
    This doesn't actually turn off the anti-aliasing. It allows you to force WPF to render graphics to match the device or display matrix, thus prevent blurrying in some cases. The effect is similar to Mac OS X vs. Windows font smoothing. – grizzly Mar 11 '14 at 11:30
4

Turning off anti-aliasing is not what you are looking for, seeing as you dont have a radius applied to the corners.

If you are using .Net 4 or above, turn on UseLayoutRounding http://msdn.microsoft.com/en-us/library/system.windows.uielement.uselayoutrounding(v=vs.95).aspx

Gusdor
  • 14,001
  • 2
  • 52
  • 64