Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Problem with StrokeDashArray (getting dotted lines)
8 replies. Latest Post by Skute on August 5, 2008.
(0)
Skute
Member
222 points
156 Posts
07-31-2008 9:16 AM |
Hi, I'm trying to draw a rectangle with a dotted line. Should be easy?
<Rectangle Stroke="#FFFFC0CB" StrokeThickness="1" StrokeDashArray="1,1"/>
According to the docs, that should draw 1 pixel on, 1 pixel gap, 1 pixel on, etc...
But for some reason, it draws a solid line all the way around the rectangle.
Is this intentional? How can I get a simple dotted line around my shape?
Thanks,
Mark
SteveWong
Contributor
6343 points
1,281 Posts
07-31-2008 12:28 PM |
For what reasons?
Maybe you can try a larger one
<Rectangle Width="100" Height="100" Stroke="Black" StrokeDashArray="10, 2"/>
pbrooks
2671 points
355 Posts
07-31-2008 12:46 PM |
If you change your StrokeThickness to a value that is greater than 1 (like 1.1 - 2.0), you will see that the dotted line starts to appear. I'm not sure why it doesn't appear at a StrokeThickness of 1.
07-31-2008 5:56 PM |
Yes I had noticed that, I tried 1.1 as the thickness and it worked ok (except it didn't look right due to anti-aliasing)
Seems like it's a bug then.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
08-04-2008 5:41 AM |
Hello, this does look like a bug. Thanks for reporting it. I'll notify our product team.
08-05-2008 12:03 AM |
Hi, I got the response from our product team. It's by design. This behavior is once again caused by anti-aliasing. In WPF, you can turn off anti-aliasing on non-text elements by setting RenderOptions.EdgeMode Attached Property to Aliased. But currently there's no way to turn off anti-aliasing in Silverlight. Maybe in the future we'll support this. But I can't give you any promise at this time...
08-05-2008 3:46 AM |
Right ok, thanks for looking into that for me. It seems like there will be no easy way to get a simple dotted line in the near future then?
08-05-2008 3:53 AM |
But if you set StrokeThickness to 1.001, it will work fine, right?
08-05-2008 6:29 AM |
No, it works on the vertical sides of a rectangle, but not on the horizontal sides of a rectangle. It ends up looking like:
----------. .. .. .----------
(i.e. solid line across top + bottom, dotted line up sides)
Code:
<Grid> <Rectangle Width="200" Height="200" Fill="LightBlue" Stroke="Salmon" StrokeThickness="1.0001" StrokeDashArray="1, 1" HorizontalAlignment="Center" VerticalAlignment="Center"/> </Grid>