Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C# (WPF) does databinding occur when the datachanges in the UI thread immediately?

Tags:

c#

.net

mvvm

wpf

I'm creating an application and I've been under the assumption that when a control is bound to a member in the view-model (i.e. a TextBox to a string field) the string is updated whenever the user changes the information in the textbox and no later.

But what I've found is that the string is updated when the textbox is changed AND when the user clicks\tabs out of the textbox.

(I'm using the Caliburn.Micro framework if that matters.)

Can someone explain which is correct and how to make it so that a change is immediately reflected?

like image 512
Scifiballer24 Avatar asked Oct 16 '10 06:10

Scifiballer24


1 Answers

This is not a WPF issue... it totally lies with the controls.

But what I've found is that the string is updated when the textbox is changed AND when the user clicks\tabs out of the textbox.

This is specific textbox to reduce the amounts of set operations and avoid setting incomplete data.

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c3ae2677-7cc9-4bb3-9cce-4e7c0eeff6f0 has a solution - basically update source trigger is set to property changed. If you do that, though, you get a lot more invalid data into the model, like for example when people enter an invocie number all the partials will be going to the model.

http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger.aspx has a nice explanation - klike it says, normal trigger is PropertyChanged, while the text property defaults to LostFocus.

like image 128
TomTom Avatar answered Oct 17 '22 02:10

TomTom