DevExpress WPF Area 颜色渐变

啥也不说,直接上代码

public class GradientArea2D: AreaSeries2D
    {
        public static readonly DependencyProperty NewAreaColorProperty = DependencyPropertyManager.Register("NewAreaColor",
            typeof(LinearGradientBrush), typeof(GradientArea2D), new PropertyMetadata(null));

        public Brush NewAreaColor
        {
            get { return (Brush)GetValue(NewAreaColorProperty); }
            set { SetValue(NewAreaColorProperty, value); }
        }
        protected override Color GetPointOriginalColorForCustomDraw(IRefinedSeries refinedSeries, int pointIndex, Color seriesColor)
        {
            return base.GetPointOriginalColorForCustomDraw(refinedSeries, pointIndex, Color.FromRgb(0,0,0));
        }

        protected override AdditionalSeriesGeometryContainer CreateAdditionalGeometry()
        {
            return new MyAdditionalAreaSeriesGeometryContainer(this);
        }
    }

    public class MyAdditionalAreaSeriesGeometryContainer: AdditionalSeriesPointGeometryContainer
    {
        public MyAdditionalAreaSeriesGeometryContainer(XYSeries series)
            : base(series)
        {
        }

        protected override void PopulateChildren(UIElementCollection children, XYSeries series)
        {
            children.Add(new MyAdditionalAreaSeriesGeometry(series));
            children.Add(new AdditionalAreaBorderSeriesGeometry(series));
            base.PopulateChildren(children, series);
        }
    }

    public class MyAdditionalAreaSeriesGeometry: AdditionalAreaSeriesGeometry
    {
        public MyAdditionalAreaSeriesGeometry(XYSeries series) : base(series)
        {
        }

        protected override void RenderCore(DrawingContext drawingContext, IEnumerable geometryList, Transform transform)
        {
            foreach (SeriesAdditionalGeometry geometry in geometryList)
            {
                if (geometry.Clip != null)
                    drawingContext.PushClip(geometry.Clip);
                Geometry renderGeometry = CalculateRenderGeometry(geometry.Geometries, transform);
                Brush areaBrush = getColor();
                drawingContext.DrawGeometry(areaBrush, null, renderGeometry);
                if (geometry.Clip != null)
                    drawingContext.Pop();
            }
        }

        Brush getColor()
        {
            GradientArea2D area2D = Series as GradientArea2D;
            return area2D.NewAreaColor;
        }
    }

你可能感兴趣的:(.NET,DevExpress)