WPF achieve cool trends

surroundings:

    System: Window 7 above;

    Tools: VS2013 and above.

R & D and engineering Language:

     C # WPF application

effect:

Summary:

    The Dll no need to call a third party, only the Bezier curve WPF, less than 500 lines of code to build custom trend effects.

principle:

    Data of the WPF path Path is PathGeometry. Such as:

  <Path x:Name="PathData1" Stroke="#FFEE4141" StrokeThickness="2">
       <Path.Fill>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" Opacity="0.5">
                <GradientStop Color="#FFEE4141" Offset="0"/>
                <GradientStop Color="#7F031528" Offset="1"/>
            </LinearGradientBrush>
       </Path.Fill>
       <Path.Data>
            <PathGeometry x:Name="PgData1"/>
       </Path.Data>
  </Path>

PathGeometry.Figures的Value类型为PathFigureCollection;即PathFigure对象的集合,将一系列的Point数据已构建Beizer曲线的形式处理后生成PathFigureCollection对象,最终以PathGeometry对象赋值给Path.Data即可实现如上述所示的效果。

主要处理函数:

private void SetPathData(PathGeometry geo, List<Point> points)
{
    var myPathFigure = new PathFigure { StartPoint = points.FirstOrDefault() };
    var myPathSegmentCollection = new PathSegmentCollection();
    var beizerSegments = BeizerUtils.InterpolatePointWithBeizerCurves(points, false);

    if (beizerSegments == null || beizerSegments.Count < 1)
    {
        foreach (var point in points.GetRange(1, points.Count - 1))
        {
            var myLineSegment = new LineSegment { Point = point };
            myPathSegmentCollection.Add(myLineSegment);
        }
    }
    else
    {
        for (int i = 0; i < beizerSegments.Count; i++)
        {
            BeizerCurveSegment beizerCurveSegment = beizerSegments[i];
            PathSegment segment = new BezierSegment
            {
                Point1 = beizerCurveSegment.FirstControlPoint,
                Point2 = beizerCurveSegment.SecondControlPoint,
                Point3 = beizerCurveSegment.EndPoint
            };
            myPathSegmentCollection.Add(segment);
        }
    }

    myPathFigure.Segments = myPathSegmentCollection;

    var myPathFigureCollection = new PathFigureCollection { myPathFigure };
    geo.Figures = myPathFigureCollection;
}
 Source download: Get the link at the end of the article under the Fanger Wei code scanning micro letter.

                           

Guess you like

Origin www.cnblogs.com/duel/p/extendchart.html