using System;
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Android.Graphics;
using Shared.UserManagment.Controls;
[assembly: ExportRenderer(typeof(RoundedBox), typeof(<Name Space Name>.RoundedBoxRenderer))]
namespace <Name Space Name>
{
public class RoundedBoxRenderer : BoxRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
{
base.OnElementChanged(e);
SetWillNotDraw(false);
Invalidate();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == RoundedBox.CornerRadiusProperty.PropertyName)
{
Invalidate();
}
}
public override void Draw(Canvas canvas)
{
//Xamarin.Forms.Color.Transparent
var box = Element as RoundedBox;
var rect = new Rect();
var paint = new Paint()
{
Color = box.BackgroundColor.ToAndroid(),
AntiAlias = true,
};
//paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.DstAtop));
GetDrawingRect(rect);
var radius = (float)(rect.Width() / box.Width * box.CornerRadius);
paint.SetStyle(Paint.Style.Stroke);
paint.StrokeWidth = 2;
canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
//paint.Color = Xamarin.Forms.Color.Black.ToAndroid();
//canvas.DrawCircle(10,10,40, paint);
}
}
}
using System.ComponentModel;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Android.Graphics;
using Shared.UserManagment.Controls;
[assembly: ExportRenderer(typeof(RoundedBox), typeof(<Name Space Name>.RoundedBoxRenderer))]
namespace <Name Space Name>
{
public class RoundedBoxRenderer : BoxRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
{
base.OnElementChanged(e);
SetWillNotDraw(false);
Invalidate();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == RoundedBox.CornerRadiusProperty.PropertyName)
{
Invalidate();
}
}
public override void Draw(Canvas canvas)
{
//Xamarin.Forms.Color.Transparent
var box = Element as RoundedBox;
var rect = new Rect();
var paint = new Paint()
{
Color = box.BackgroundColor.ToAndroid(),
AntiAlias = true,
};
//paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.DstAtop));
GetDrawingRect(rect);
var radius = (float)(rect.Width() / box.Width * box.CornerRadius);
paint.SetStyle(Paint.Style.Stroke);
paint.StrokeWidth = 2;
canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
//paint.Color = Xamarin.Forms.Color.Black.ToAndroid();
//canvas.DrawCircle(10,10,40, paint);
}
}
}
No comments:
Post a Comment