Let's say that you want to draw a line in WPF. You'd probably guess that there is a Line class in WPF that does the trick. You'd be right, as it turns out, there is such a class available in WPF. To use it you designate a start and end point, provide a color and line thickness and you get your desired line.

Were you aware that WPF includes another line class? It's called the Polyline and the primary difference is that you provide a collection of Points, typed as a PointCollection, to the Polyline and it draws a line through each point.

Here's how you do that in XAML.

image

image

You can also add points in your application code like this example.

image

image 

Changing the StrokeLineJoin property

You can control the shape of the Polyline where it changes direction with the StrokLineJoin property. Choose from the three values; Round, Bevel and Miter.

image 

image

Dynamically adding Points

If you want to allow your users to draw a poly line on screen it easy to accomplish with the following code.

image

image

 

Creating a dynamic line chart

This last example shows show to create a dynamic line chart. The interesting idea in this chart example is how it updates. When the timer fires a new Point is added to the Points collection. Then the first point in the collection is removed. Next, each point in the point collection has its X coordinate reduced by a constant amount. The effect is that the chart appears to move constantly to the left.

image

Source Code

https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=WintellectPolyline&ReleaseId=4601