protected override void OnElementChanged(ElementChangedEventArgs <ContentView> e) { base.OnElementChanged(e); if (e.NewElement != null && e.OldElement == null) { var pancake = (Element as CanvasView); // HACK: When there are no children we add a Grid element to trigger DrawChild. // This should be improved upon, but I haven't found out a nice way to be able to clip // the children and add the border on top without using DrawChild. if (pancake.Content == null) { pancake.Content = new Grid(); } Validate(pancake); this.SetBackground(_drawable = new CanvasDrawable(pancake, Context.ToPixels)); SetupShadow(pancake); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { var pancake = Element as CanvasView; Validate(pancake); base.OnElementPropertyChanged(sender, e); if (e.PropertyName == CanvasView.BorderColorProperty.PropertyName || e.PropertyName == CanvasView.BorderThicknessProperty.PropertyName || e.PropertyName == CanvasView.BorderIsDashedProperty.PropertyName || e.PropertyName == CanvasView.BorderDrawingStyleProperty.PropertyName || e.PropertyName == CanvasView.BorderGradientAngleProperty.PropertyName || e.PropertyName == CanvasView.BorderGradientEndColorProperty.PropertyName || e.PropertyName == CanvasView.BorderGradientStartColorProperty.PropertyName || e.PropertyName == CanvasView.BorderGradientStopsProperty.PropertyName) { Invalidate(); } else if (e.PropertyName == CanvasView.SidesProperty.PropertyName || e.PropertyName == CanvasView.OffsetAngleProperty.PropertyName || e.PropertyName == CanvasView.HasShadowProperty.PropertyName || e.PropertyName == CanvasView.ElevationProperty.PropertyName) { SetupShadow(pancake); } else if (e.PropertyName == CanvasView.CornerRadiusProperty.PropertyName) { Invalidate(); SetupShadow(pancake); } else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) { _drawable.Dispose(); this.SetBackground(_drawable = new CanvasDrawable(pancake, Context.ToPixels)); } }