protected override void OnElementChanged(ElementChangedEventArgs <Image> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } try{ CustomCircleImage circle = (CustomCircleImage)Element; double min = Math.Min(Element.Width, Element.Height); Control.Layer.CornerRadius = (float)(min / 2.0); Control.Layer.MasksToBounds = false; Control.Layer.BorderColor = new CGColor(circle.rgb.r, circle.rgb.g, circle.rgb.b); Control.Layer.BorderWidth = 3; Control.ClipsToBounds = false; }catch (Exception ex) { } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName) { try{ CustomCircleImage circle = (CustomCircleImage)Element; double min = Math.Min(Element.Width, Element.Height); Control.Layer.CornerRadius = (float)(min / 2.0); Control.Layer.MasksToBounds = false; Control.Layer.BorderColor = new CGColor(circle.rgb.r, circle.rgb.g, circle.rgb.b); Control.Layer.BorderWidth = 3; Control.ClipsToBounds = true; } catch (Exception ex) { } } }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try{ var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; Path path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); CustomCircleImage circle = (CustomCircleImage)Element; var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.Rgb(circle.rgb.r, circle.rgb.g, circle.rgb.b); // = global::Android.Graphics.Color.Pink; canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); return(result); }catch (Exception ex) { } return(base.DrawChild(canvas, child, drawingTime)); }