Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF listview databinding - How do I force update to underlying object without tabbing out?

Tags:

wpf

I have a WPF ListView that is bound to a BindingList<T>. The binding works like a charm, but I have to tab out of the cell to get the bound property to update....this is an issue because most users don't tab out of the last column before clicking the save button.

How do I force the list view to "persist" the changes to the bound DataContext without doing something hackish.

like image 968
Amir Avatar asked Nov 26 '08 04:11

Amir


1 Answers

Bindings in WPF have a property called "UpdateSourceTrigger" which tells the Binding when to update the thing the UI is bound to. By default, it's set to "LostFocus" for the Text property which is what you're most likely using.

Change the trigger to "PropertyChanged" in your binding like this:

Text="{Binding Foo,UpdateSourceTrigger=PropertyChanged}"

... and now the source "Foo" property will be updated as the Text changes in the UI.

There's also an "Explicit" setting for UpdateSourceTrigger which is handy if you need to hold off writing any changes to the source until, say, the user clicks the OK button.

like image 176
Matt Hamilton Avatar answered Oct 06 '22 01:10

Matt Hamilton