CustomEntry.cs
using System;
using Xamarin.Forms;
namespace PROSHIP4GUEST
{
public class CustomEntry : Entry
{
public CustomEntry ()
{
}
public static readonly BindableProperty ImageStartProperty =
BindableProperty.Create<CustomEntry,ImageSource> (
p => p.ImageStart, default(ImageSource));
public ImageSource ImageStart {
get { return (ImageSource)GetValue (ImageStartProperty); }
set { SetValue (ImageStartProperty, value); }
}
}
}
Using in ContentPage
CustomEntry userCus = new CustomEntry {
ImageStart = ImageSource.FromFile("email.png")
};
CustomEntryRenderer for Android
using System;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using PROSHIP4GUEST;
using PROSHIP4GUEST.Droid;
using Android.Graphics;
using System.Security.Cryptography;
using System.Threading.Tasks;
[assembly: ExportRendererAttribute(typeof(CustomEntry),typeof(CustomEntryRenderer))]
namespace PROSHIP4GUEST.Droid
{
public class CustomEntryRenderer : EntryRenderer
{
private Bitmap hix;
public CustomEntryRenderer ()
{
this.SetWillNotDraw (false);
hix = BitmapFactory.DecodeResource (this.Context.Resources, Resource.Drawable.email);
}
private static IImageSourceHandler GetHandler(ImageSource source)
{
IImageSourceHandler returnValue = null;
if (source is UriImageSource)
{
returnValue = new ImageLoaderSourceHandler();
}
else if (source is FileImageSource)
{
returnValue = new FileImageSourceHandler();
}
else if (source is StreamImageSource)
{
returnValue = new StreamImagesourceHandler();
}
return returnValue;
}
private async Task<Bitmap> GetBitmapAsync(ImageSource source)
{
var handler = GetHandler(source);
var returnValue = (Bitmap)null;
returnValue = await handler.LoadImageAsync(source, this.Context);
return returnValue;
}
protected override void OnElementChanged (ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged (e);
if (Control != null) {
Control.SetPadding (40, 0, 0, 0);
}
}
public override async void Draw (Canvas canvas)
{
base.Draw (canvas);
CustomEntry ce = (CustomEntry)this.Element;
Paint p = new Paint ();
Bitmap bmp = await GetBitmapAsync(ce.ImageStart);
canvas.DrawBitmap (hix,0,0,p);
}
}
}
But it not working, app stop when i start. How to fix this, thanks.
I want to make Entry like this