我正在尝试在网格上使用渐变画笔作为背景。到目前为止,我只为 UWP 创建了一个自定义渲染器,但我无法让它工作。
e.NewElement.BackgroundColor 需要一个颜色,但我有一个 LinearGradientBrush。那么甚至可以将网格背景设置为渐变色吗?
谢谢
我的渲染器代码如下:
public class MyGridRenderer:ViewRenderer<MyGrid, Grid>
{
protected override void OnElementChanged(ElementChangedEventArgs<MyGrid> 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 goes here
//Control.Background = brush;
}
}
}