Skip to main content

Microsoft Silverlight

Unanswered Question Problem with StrokeDashArray (getting dotted lines)RSS Feed

(0)

Skute
Skute

Member

Member

222 points

156 Posts

Problem with StrokeDashArray (getting dotted lines)

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
SteveWong

Contributor

Contributor

6343 points

1,281 Posts

Re: Problem with StrokeDashArray (getting dotted lines)

For what reasons?

Maybe you can try a larger one

 <Rectangle Width="100" Height="100" Stroke="Black" StrokeDashArray="10, 2"/>

Regards,
SteveWong (HongKong)
Please mark post as answer if they help you

Client App Dev

pbrooks
pbrooks

Contributor

Contributor

2671 points

355 Posts

Silverlight MVP

Re: Problem with StrokeDashArray (getting dotted lines)

 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.

If this has answered your question, please click on "Mark as Answer" on this post.

Thanks,
Page Brooks
Silverlight MVP, MCSD
PageBrooks.com | @pbrooks

Skute
Skute

Member

Member

222 points

156 Posts

Re: Problem with StrokeDashArray (getting dotted lines)

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 Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Problem with StrokeDashArray (getting dotted lines)

Hello, this does look like a bug. Thanks for reporting it. I'll notify our product team.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Re: Problem with StrokeDashArray (getting dotted lines)

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...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Skute
Skute

Member

Member

222 points

156 Posts

Re: Re: Problem with StrokeDashArray (getting dotted lines)

 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?

Thanks,

Mark

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Re: Re: Problem with StrokeDashArray (getting dotted lines)

But if you set StrokeThickness to 1.001, it will work fine, right?

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Skute
Skute

Member

Member

222 points

156 Posts

Re: Re: Re: Problem with StrokeDashArray (getting dotted lines)

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>

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities