[C# Helper]
Index Books FAQ Contact About Rod
[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[Beginning Software Engineering]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Use a custom dash pattern with WPF and XAML in C#

[Use a custom dash pattern with WPF and XAML in C#]

My post Render dashed lines in a WPF program using C# explains how a WPF program can use C# code to render lines with a custom dash pattern onto a bitmap. This post shows how to use a custom dash pattern min XAML code.

The key is to use a StrokeDashArray property to define a line's dash pattern. This program uses the following code to draw its curve.

<Path Stroke="Red" StrokeThickness="5" StrokeDashArray="10,1,1,1" Data="M 175,10 C -100,150 400,200 70,30"> </Path>

The custom dash pattern 10,1,1,1 means the line should draw 10 units, skip 1 unit, draw 1 unit, skip 1 unit, and then repeat.

Note that the units are equal to the width of the line. In this example, the line is 5 pixels wide so each unit is 5 pixels. that means this custom dash pattern makes the line draw 50 pixels, skip 5 pixels, draw 5 pixels, skip 5 pixels, and repeat.

Download the example to experiment with it and to see additional details.

© 2009-2022 Rocky Mountain Computer Consulting, Inc. All rights reserved.