How to draw a smooth curved line in WPF?

.net, c#, canvas, wpf

Solution

I think you are looking for splines

http://msdn.microsoft.com/en-us/library/554h284b.aspx

Gabe is correct that is from Forms

Under WPF you could try a PolyBezierSegment but it require 4 points. Possible you could put in three points and 1 more to shape it.

<Canvas>
    <Path Stroke="Black" StrokeThickness="10">
        <Path.Data>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigureCollection>    
                        <PathFigure StartPoint="100,80">
                            <PathFigure.Segments>
                                <PathSegmentCollection>
                                    <PolyBezierSegment Points="90,200 140,200 160,200 180,200 430,190 430,280" />
                                </PathSegmentCollection>
                            </PathFigure.Segments>
                        </PathFigure>
                    </PathFigureCollection>
                </PathGeometry.Figures>
            </PathGeometry>
        </Path.Data>
    </Path>
</Canvas>

This results in the following curve

Problem

I have three known positions, and currently I am driving two lines like so: ``` Line line = new Line { StrokeThickness = 3, Stroke = lineColor, X1 = MyX, Y1 = MyY, X2 = MyX, Y2 = MiddleY }; Graph.Children.Add(line); line = new Line { StrokeThickness = 3, Stroke = lineColor, X1 = MyX, Y1 = MiddleY, X2 = TargetX, Y2 = TargetY }; Graph.Children.Add(line); ``` Here's the result: So, as you can see, this is almost what I want except that I want it to be more smoothed out, just a little bit. Now I'm looking for any way I could set three points, set some smooth/curvy level to the middle point and then draw a line with a solid color on it. Much like how I can do this in Photoshop: Or at least get a similar kind of smoothness.

Original source

Related problems