What event should be used to update the model from TextBox (LostFocus, LostKeyboardFocus, etc.) in WPF? How to set event priority in WPF?

I have an application in which there are many text fields and some buttons like Save, SaveAs, etc.

When a user edits a TextBox, I have to check the database for some range, check the range and update the database. If there is any error in the value entered by the user, then I should not allow the TextBox to lose focus.

I used the LostFocus event to do this, and it worked fine until recently I found an error in my application.

Error: The user edits the value in the TextBox and then clicks the "Save" button; LostFocus event is not raised and therefore the database is not updated :(

Now my question is: what event should I use in the TextBox to update the database. I tried the TextChanged event, but it checks for each character and slows down the application. I am confused about choosing the right event for this kind of application!

Note : ** Buttons are in different UserControl!

EDIT 1: I have some commands attached to the Buttons buttons, these commands run until LostFocus !! Can I set the priority or something like the attached behavior or the commands should be executed after LostFocus !!

EDIT 2: , . , DelegateCommand LostFocus, . ? , MVVM, !

+3
2

- , , .

, . Windows Forms WPF. WPF.

, , .. string Command (, , a RelayCommand) "". , :

<TextBox Text="{Binding MyTextProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

UpdateSourceTrigger - PropertyChanged, , .

, :

<Button CommandBinding="{Binding SaveCommand}">Save</Button>

CanSave Save, RelayCommand ( MVVM ) , , , .

+1

, - , .

Terms & Conditions Dialog Next. I Agree, Next .

, . , TextBox .

+1

Source: https://habr.com/ru/post/1780368/


All Articles