Gradient as background on a grid

Hi,

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?

Thanks

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)
{
base.OnElementChanged(e);

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

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

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


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

}`

Best Answer

Answers

Sign In or Register to comment.