WPFは、クールなトレンドを達成します

環境:

    システム:上記窓7。

    ツール:VS2013以上。

R&Dとエンジニアリング言語:

     C#WPFアプリケーション

効果:

要約:

    Dllファイルには、サードパーティのみベジェ曲線WPF、カスタムのトレンドの影響を構築するためのコードの500の未満の行を呼び出す必要がありません。

原理:

    WPFパスパスのデータがPathGeometryをです。以下のような:

  <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(セグメント)。
        } 
    } 

    myPathFigure.Segments = myPathSegmentCollection。

    VaRの myPathFigureCollection = 新しいPathFigureCollection {myPathFigure}。
    geo.Figures = myPathFigureCollection。
}
 ソースのダウンロード:Fanger魏コードスキャンマイクロ文字の下に記事の最後にあるリンクを取得します。

                           

おすすめ

転載: www.cnblogs.com/duel/p/extendchart.html