Forum Xamarin Xamarin.Forms

Xamarin.Forms : Entry field textChanged event.


In xamarin form Entry control , TextChanged event Entry1 _TextChanged(object sender, TextChangedEventArgs e) , we have "OldTextValue" & "NewTextValue" in event args.

based on some condition i have to replace new value with old value for that i have used below code,

e.OldTextValue = e.NewTextValue;

but this end in multiple or some times infinite loop, as each time old & new values are interchanged.

is there any way handle the event as true as we do in wpf.


Best Answer


  • AndrewMobileAndrewMobile USMember ✭✭✭✭
    edited June 2015

    e is the argument passed to your event handler.
    the code you pasted
    e.OldTextValue = e.NewTextValue;
    is invalid

    it's not possible to set e.OldTextValue value

  • Madhu.2604Madhu.2604 USMember

    Hey thanks for your reply its my mistake , wrongly typed here , it should be

    entryField.Text = e.OldTextValue;

    this triggers event to fire multiple times.

  • TorbenKruseTorbenKruse DEMember ✭✭✭

    I don't really like it, and there must be another way to handle this, but the fastest way to fix this would be to unsubscribe the event before changing the text inside your event handler and then resubscribe. Something like this:

    Entry1 _TextChanged(object sender, TextChangedEventArgs e)
            entryField.TextChanged -= Entry1 _TextChanged;
            entryField.Text = e.OldTextValue;
            entryField.TextChanged += Entry1 _TextChanged;

    I'm pretty sure there is also a way to handle this via bindings.

  • kenneth.leekenneth.lee USMember ✭✭✭
    edited September 2017

    I know this is 2 years ago, but would a better indirect solution be to disable the entry?

    Edit: nevermind i realise why that wouldn't be a good solution

Sign In or Register to comment.