Search code examples
xamarinxamarin.androidxamarin.formspicker

TailTruncation - Ellipsize the text of a picker control in Xamarin Forms


Is it possible to truncate long texts with ellipsis in a picker control. I have already created a custom renderer to set a fontsize and no border in order to achieve the following result.

enter image description here

Also tried to set Control.Ellipsize = TextUtils.TruncateAt.End; but nothing happens

[assembly: ExportRenderer(typeof(NoBorderPicker), typeof(CustomPicker))]
namespace Prj.Droid.Renderers
{
    public class CustomPicker : PickerRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {

                var customBG = new GradientDrawable();
                customBG.SetColor(Android.Graphics.Color.Transparent);
                customBG.SetCornerRadius(3);
                Control.SetBackground(customBG);

                Control.Ellipsize = TextUtils.TruncateAt.End;

                var custdatepicker = (NoBorderPicker) this.Element;
                this.Control.TextSize = (float)custdatepicker.FontSize;

            }
        }
    }
}

Solution

  • Now, I could be sure that Control.SetSingleLine(true); will work.