I have a problem with the TextChanged event of an entry.
I added an event handler for this event to check the entered character for correctness. If it is not allowed I remove it and rewrite the string into the entry. This rewriting again calls the TextChanged event. To avoid the second call, I remove the event handler before setting the new text and add it after setting the new text:
entry.TextChanged -= MyTextChangedEvent; entry.Text = updatedText; entry.TextChanged += MyTextChangedEvent;
This unfortunately doesn't seem to work. MyTextChangedEvent is still invoked twice. When I add a short Task.Delay, it works though:
entry.TextChanged -= MyTextChangedEvent; entry.Text = updatedText; await Task.Delay(1); entry.TextChanged += MyTextChangedEvent;
Can anybody tell me what I do wrong? From the solutions found in this forum the Task.Delay() shouldn't be necessary.
Thank you in advance.