Posted 7 March 2023, 5:44 am EST
public override void draw(GcSvgDocument svgDoc, SvgGradientElement svgG)
{
svgDoc.RootSvg.Children.Add(svgG.Fill = ( new SvgPaint(new SvgColor(Color.Black)) }) );
}
Forums Home / ComponentOne / General Discussion
Posted by: vimalkumar.panneerselvam on 7 March 2023, 5:44 am EST
Posted 7 March 2023, 5:44 am EST
public override void draw(GcSvgDocument svgDoc, SvgGradientElement svgG)
{
svgDoc.RootSvg.Children.Add(svgG.Fill = ( new SvgPaint(new SvgColor(Color.Black)) }) );
}
Posted 26 June 2023, 5:22 am EST
Hi,
Thanks for reaching out to us.
There are two types of SvgGradientElement:
You can append a GradientElement in SVG and then you can Fill any element with that Gradient using SvgReference.(see code below)
//Append Gradient
var svgDef = new SvgDefsElement();
var svgLinearGradient = new SvgLinearGradientElement() { ID = "grad1", X1 = new SvgLength(0,SvgLengthUnits.Percentage), Y1 = new SvgLength(0, SvgLengthUnits.Percentage), X2 = new SvgLength(0, SvgLengthUnits.Percentage), Y2 = new SvgLength(100, SvgLengthUnits.Percentage) };
svgLinearGradient.Children.Add(new SvgStopElement() { Offset = 0, StopColor = new SvgColor(Color.Red), StopOpacity = 1 });
svgLinearGradient.Children.Add(new SvgStopElement() { Offset = 100, StopColor = new SvgColor(Color.Yellow), StopOpacity = 1 });
svgDef.Children.Add(svgLinearGradient);
svg.RootSvg.Children.Add(svgDef);
//Apply Gradient on a existing element
var ellipse =svg.RootSvg.Children[0] as SvgEllipseElement;
ellipse.Fill = new SvgPaint(new SvgReference("grad1"));
Please refer the attached sample for the same: GradientSvg.zip
Best Regards,
Nitin