mshwf
mshwf

Reputation: 7449

Unexpected behavior of the Xamarin Picker when using custom renderer?

I need to customize the Text color of the picker (the Title color), which is not possible in the Xamarin.Forms implementation, so I created a simple renderer which did what I needed:

using Android.Content;
using MyProj.Droid.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(Picker), typeof(CustomPickerRenderer))]
namespace MyProj.Droid.Renderers
{
    public class CustomPickerRenderer : PickerRenderer
    {
        public CustomPickerRenderer(Context context) : base(context) { }
        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.SetHintTextColor(((Color)Application.Current.Resources["TextColor"]).ToAndroid());
            }
        }
    }
}

but the style of the control has changed significantly, so instead of a list that respond to the tap gesture on any item, it becames a scrollable list that only respond to the OK/ Cancel buttons!

Images:

expected style (before using the custom renderer):

enter image description here

the unexpected style (after using the custom renderer): enter image description here

Upvotes: 0

Views: 383

Answers (1)

Jannik R.
Jannik R.

Reputation: 176

your custom renderer needs to be inherited from Xamarin.Forms.Platform.Android.AppCompat.PickerRenderer instead of Xamarin.Forms.Platform.Android.PickerRenderer to have the expected style.

Upvotes: 3

Related Questions