Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How to read a backspace in an Entry from Xamarin.Forms?

$
0
0

I can't for the life of me capture the backspace! I need to capture a backspace, even if the field is empty. Am I doing something wrong?

public class CustomEntryRenderer: EntryRenderer, Android.Views.View.IOnKeyListener
{
    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            return;
        }

        var entry = (CustomEntry)Element;

        Control.SetOnKeyListener(this);

        Control.KeyPress += (s, arg) => {
            System.Diagnostics.Debug.WriteLine("OnElementChanged KeyPress");
        };

        Control.TextChanged += (s, ev) => {
            System.Diagnostics.Debug.WriteLine("OnElementChanged TextChanged");
        };

        Control.EditorAction += (s, ev) =>
        {
            System.Diagnostics.Debug.WriteLine("EditorAction EditorAction");
        };

        Control.SetOnEditorActionListener(this);


    }

    public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e)
    {
        System.Diagnostics.Debug.WriteLine("OnKeyPreIme");
        return base.OnKeyPreIme(keyCode, e);
    }

    public override bool OnKeyUp(Keycode keyCode, KeyEvent e)
    {
        System.Diagnostics.Debug.WriteLine("OnKeyUp");
        return base.OnKeyUp(keyCode, e);

    }



    protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (Control == null)
        {
            return;
        }

        var entry = (CustomEntry)Element;

        Control.SetOnKeyListener(this);

        Control.KeyPress += (s, arg) =>
        {
            System.Diagnostics.Debug.WriteLine("OnElementPropertyChanged KeyPress");
        };

        Control.TextChanged += (s, ev) =>
        {
            System.Diagnostics.Debug.WriteLine("OnElementPropertyChanged KeyPress");
        };

        Control.EditorAction += (s, ev) => {
            System.Diagnostics.Debug.WriteLine("OnElementPropertyChanged EditorAction");
        };

    }

    bool IOnKeyListener.OnKey(Android.Views.View v, Keycode keyCode, KeyEvent e)
    {
        System.Diagnostics.Debug.WriteLine("OnKey");
        return true;
    }


}

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>