How to draw a smooth curved line in WPF?

后端 未结 2 796
小鲜肉
小鲜肉 2021-02-20 16:38

I have three known positions, and currently I am driving two lines like so:

Line line = new Line
{
    StrokeThickness = 3,
    Stroke = lineColor,
    X1 = MyX,         


        
相关标签:
2条回答
  • 2021-02-20 17:16

    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

    enter image description here

    0 讨论(0)
  • 2021-02-20 17:23

    You want to use a PathFigure, specifically with a set of BezierSegments.

    0 讨论(0)
提交回复
热议问题