SarPa
SarPa

Reputation: 45

Image Entry in Xamarin Forms

I want to be able to insert an image inside an input, make a binding if the mail is confirmed or not. I can't find any way to render the entry for IOS and android I want to achieve the followingenter image description here

I read the following but it is deprecated https://xamgirl.com/image-entry-in-xamarin-forms/

Upvotes: 0

Views: 478

Answers (1)

Alexandar May - MSFT
Alexandar May - MSFT

Reputation: 10063

Per your requirement,it could be achieved by custom control with bindable property.However, in Android Renderer, you need make small adjustments in BitmapDrawable method like below:

      private BitmapDrawable GetDrawable(string imageEntryImage)
        {
            int resID = Resources.GetIdentifier(imageEntryImage, "drawable", this.Context.PackageName);
            var drawable = ContextCompat.GetDrawable(this.Context, resID);
            var bitmap = ((BitmapDrawable)drawable).Bitmap;

            if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.P)
            {
                return new BitmapDrawable(Resources, Android.Graphics.Bitmap.CreateScaledBitmap(bitmap, element.ImageWidth * 2, element.ImageHeight * 2, true));
            }

            return new BitmapDrawable(Resources, Android.Graphics.Bitmap.CreateScaledBitmap(bitmap, element.ImageWidth, element.ImageHeight, true));
        }
    

Consume the image entry in backend:

    <local:ImageEntry TextColor="White" 
                          BackgroundColor="Aqua"
                    
                        Image="icon" 
                        Placeholder="Email" 
                        HorizontalOptions="FillAndExpand"/>

Running outcome in iOS:

enter image description here

Running outcome in Android:

enter image description here

Upvotes: 0

Related Questions