tags:

views:

3096

answers:

1

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.

+6  A: 

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.

Matt Hamilton