0

I have few Entry controls in my app, every Entry has a Lost-Focus event. There is button, it has a Click Event to process further. My problem is when user clicks the button, the Lost-Focus event of the last Entry is fired after the button-click. I want the Lost-Focus to be executed before button-Click.

So I thought to add a Application-Do-Events like something at the start of Button-Click. Please note I do not wish to Fire the Lost Focus from Button-Click as the Entry controls are created programmatically based on user inputs on the previous page.

1 Answers1

0

You mean the last Entry is focused, but you don't want to lose focus by clicking button? And for Application.Doevents(), you can use Dispacher in MAUI.

entry.Dispatcher.Dispatch(() =>
{
    entry.Unfocus();
});

// or use it directly in page.xaml.cs
//this.Dispatcher.Dispatch(() => 
Dispatcher.Dispatch(() =>
{
    entry.Unfocus();
});

For more info you can refer to these case: What is equivalent to Application.DoEvents() in WPF applications, Dispatcher.Dispatch on the UI thread, Use of Application.DoEvents(), .net MAUI c# Background Task and this.

Jianwei Sun - MSFT
  • 2,289
  • 1
  • 3
  • 7
  • E.G. There are EntryA, EntryB, EntryC,.....EntryN. Then last, there is Button. All Entry have unfocussed Event. In this unfocussed event the data in the entry is appended to a list. When the button is clicked, the list is processed further, Now the issue The entry which is focused just before button click is added to the list after the button click event is processed. and hence the data in this last focused entry is not available for further processing. Instead of using the unfocussed event of the Entry if i use the TextChanged event I get the desired result. – user5958432 Mar 27 '23 at 10:26