GodoorSun
GodoorSun

Reputation: 39

Draw the Polyline with border

I'm using WPF to draw the polyline with certain width, the sample code is as follows:

DrawingContext.DrawGeometry(Brushes.Yellow, new Pen(Brush, polylineWidth), streamGeometry);

where the streamGeometry is the geometry of the polyline. The result Looks like: enter image description here

However, I'd like to add borders around the polyline, which looks like:

enter image description here enter image description here

I know I can draw two polylines with different width (one for the black background, and the other for the color I want to render) I just wonder is there any API or some elegant way to achieve this?

Upvotes: 1

Views: 1361

Answers (1)

gomi42
gomi42

Reputation: 2519

There is only one additional step needed to accomplish that. Create a new shape out of your polyline (the thickness of the polyline included). Use:

var pathGeometry = streamGeometry.GetWidenedPathGeometry (new Pen(Brushes.Black, polylineWidth));

Then call

DrawingContext.DrawGeometry(Brushes.Yellow, new Pen(strokeBrush, strokeThickness), pathGeometry);

and you are done.

Upvotes: 2

Related Questions