First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)

In the last weeks I started playing around a bit with Silverlight in order to build something decent of the Italian Silverlight competition, so I decided to start sharing something of the things I found out while doing it.

The first one is about drawing dashed lines.

Here is how to do it in code:

Line line = new Line();
line.StrokeThickness = 1;
double[] dashArray = new double[2];
dashArray[0] = 2;
dashArray[1] = 4;
line.StrokeDashArray = dashArray;

All you need is to define an array of double, size 2, and set the length of the dash as first element and the spacing between to dashes as second element of the array.

Both values are specific to the thickness of the line being drawn, so {1,1} will draw a dotted line (actually a dashed lines with square dashes).

And you want to draw more complex dashed lines, for example like the ones used in technical drawings, you can add to the array other couples of doubles, and draw dash-dot sequences: every even values is the length of dashes, odd values specifies gaps.

I'll try to post some more bits in the next weeks (even if the competition deadline is in 3 days, I'll go on developing the control Daniela and I are building).

Technorati Tag: ,
posted on Friday, January 25, 2008 10:22 PM
Comments have been closed on this topic.