FrameRenderer crash with Binding

Hy, i'd create a Custom control for frame to create a gradient background. It works fine if i set static color(StartColor and EndColor) but if i bind with converters, app crashes. This is my code:

  1. Renderer
  • public class FrameGradientRenderer : VisualElementRenderer
  • {
  • private Color StartColor { get; set; }
  • private Color EndColor { get; set; }
  • protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
  • {
  • var gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,
  • this.StartColor.ToAndroid(),
  • this.EndColor.ToAndroid(),
  • Android.Graphics.Shader.TileMode.Mirror);
  • var paint = new Android.Graphics.Paint()
  • {
  • Dither = true,
  • };
  • paint.SetShader(gradient);
  • canvas.DrawPaint(paint);
  • base.DispatchDraw(canvas);
  • }
  • protected override void OnElementChanged(ElementChangedEventArgs e)
  • {
  • base.OnElementChanged(e);
  • if (e.OldElement != null || Element == null)
  • {
  • return;
  • }
  • try
  • {
  • var frame = e.NewElement as FrameGradient;
  • this.StartColor = frame.StartColor;
  • this.EndColor = frame.EndColor;
  • }
  • catch (Exception ex)
  • {
  • System.Diagnostics.Debug.WriteLine(@ERROR:, ex.Message);
  • }
  • }
  • }
  1. CustomControl
  • public class FrameGradient : Frame
  • {
  • public Color StartColor { get; set; }
  • public Color EndColor { get; set; }
  • }
  1. Xaml
Sign In or Register to comment.