WynApse Home Page
Home    Blog    About    Contact       
Latest Article:


My Tags:
My Sponsors:






Lifetime Member:

<SilverlightTooltip Number="001" Text="StrokeThickness 1" />






StrokeThickness="1" isn't always 1

Compare the Lines and Paths in the canvas above. I've drawn them horizontally to prove my point. Logic tells us that drawing a single-pixel straight line horizontally or vertically should be very simple, I mean we can do that with MS Paint!

You don't even have to zoom in on that to see that the lines appear to vary in thickness because of antialiasing, yet the StrokeThickness on all is explicitly set to "1".

If you start or end your object at location 10 or 10.0, you're guaranteed to get antialiasing. If you start on 10.5 or 10.6, you'll get what you're wanting -- even with a diagonal line, as can be seen with the green lines.

I have actually discussed this before and in somewhat different detail in an article named Silverlight Rectangles, Paths, and Line Comparison.

XAML for producing this page:

<Canvas 
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<TextBlock FontSize="12" Text=".0 Line:" />
<Line X1="45" Y1="10" X2="200" Y2="10" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="10" FontSize="12" Text=".1 Path:" />
<Path Data="M45.1,20.1 L200.1,20.1" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="20" FontSize="12" Text=".2 Line:" />
<Line X1="45.2" Y1="30.2" X2="200.2" Y2="30.2" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="30" FontSize="12" Text=".3 Path:" />
<Path Data="M45.3,40.3 L200.3,40.3" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="40" FontSize="12" Text=".4 Line:" />
<Line X1="45.4" Y1="50.4" X2="200.4" Y2="50.4" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="50" FontSize="12" Text=".5 Path:" />
<Path Data="M45.5,60.5 L200.5,60.5" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="60" FontSize="12" Text=".6 Line:" />
<Line X1="45.6" Y1="70.6" X2="200.6" Y2="70.6" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="70" FontSize="12" Text=".7 Path:" />
<Path Data="M45.7,80.7 L200.7,80.7" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="80" FontSize="12" Text=".8 Line:" />
<Line X1="45.8" Y1="90.8" X2="200.8" Y2="90.8" StrokeThickness="1" Stroke="Blue" />

<TextBlock Canvas.Top="90" FontSize="12" Text=".9 Path:" />
<Path Data="M45.9,100.9 L200.9,100.9" StrokeThickness="1" Stroke="Blue" />

<Path Data="M45.5,20.5 L200.5,80.5" StrokeThickness="1" Stroke="Green" />
<Line X1="45.6" Y1="30.6" X2="200.6" Y2="90.6" StrokeThickness="1" Stroke="Green" />

</Canvas>


Stay in the 'Light!
Copyright © 2006-2017, WynApse