How to draw a Bezier curve programmatically in WPF?

mike picture mike · Aug 17, 2009 · Viewed 12.1k times · Source

I need to write a simple WPF program to draw a Bezier curve, but I have to draw it programmatically since I need to allow user to modify the shape interactively.

Any code sample to do this task is highly appreciated!

Thanks,

Mike

Answer

Drew Noakes picture Drew Noakes · Aug 17, 2009

Have a look at the Path Markup Syntax to get a feel for the raw drawing primitives available to you in WPF.

You could use either cubic or quadratic Bezier curves (each has a smoothed version too) depending on how you want to define the control points.

As for rendering the control points on screen and allowing the user to drag them about you might like to look into adorners and possibly the Thumb class.