Automatically select all text on focus Xamarin

Ibrahim picture Ibrahim · Jan 28, 2015 · Viewed 9.3k times · Source

How to automatically select all text on focus in Entry,Editor,Label? Use Cross Platforms.

Quantity.IsFocused = true; 

No work :(

Answer

Ibrahim picture Ibrahim · Jan 29, 2015

In MainActivity add

public class MyEntryRenderer : EntryRenderer
{
    public MyEntryRenderer(Context ctx) : base(ctx) {}
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);
        if (e.OldElement == null)
        {
            var nativeEditText = (EditText)Control;
            nativeEditText.SetSelectAllOnFocus(true);
        }
    }
}

and to the top add :

[assembly: ExportRenderer (typeof (Entry), typeof (MyEntryRenderer))]