Gradient as background on a grid


I'm trying to use a gradient brush for a background on a Grid. So far I've created a custom renderer for the UWP only but I can't get that to work.

The e.NewElement.BackgroundColor expects a Color, but I have a LinearGradientBrush. So is it even possible to set the grid background as a gradient color?


My renderer code is below:

`[assembly: ExportRenderer(typeof(MyGrid), typeof(MyGridRenderer))]
namespace CustomRenderingControls.UWP
public class MyGridRenderer:ViewRenderer<MyGrid, Grid>
protected override void OnElementChanged(ElementChangedEventArgs e)

        if (e.NewElement != null)
            LinearGradientBrush brush = new LinearGradientBrush();

            GradientStop start = new GradientStop();
            start.Offset = 0;
            start.Color = Colors.Yellow;

            GradientStop stop = new GradientStop();
            stop.Offset = 1;
            stop.Color = Colors.Black;

            e.NewElement.BackgroundColor = brush; //(What should I do here!!!!)
            //Control.Background = brush;


Best Answer


Sign In or Register to comment.