Problem with a chart with a polyline and a LinearGradientBrush
- by Maurizio Reginelli
I have a graph with a polyline contained into a canvas. I would like to set the stroke of the polyline starting from a color at the bottom and ending to another color on top. I tried with this xaml:
<Polyline StrokeThickness="2">
<Polyline.Stroke>
<LinearGradientBrush StartPoint="0.5,1" EndPoint="0.5,0">
<GradientStop Color="Blue" Offset="0" />
<GradientStop Color="Cyan" Offset="1" />
</LinearGradientBrush>
</Polyline.Stroke>
</Polyline>
In this way it works but the height of the gradient is equal to the height of the polyline. I mean, if I have a polyline which goes from the bottom of the canvas to its top, the gradient is applied over the entire height of the canvas. If I have instead a horizontal polyline, the gradient is applied to its thickness.
I would like to have a gradient height equal to the canvas height, independently from the polyline height.
How can I achieve this?