views:

186

answers:

1

I'm working with VS2010, WPF and EF. I've placed controls on my window by dragging an entity out of the Data Sources toolwindow. I used the "details" setting so my entity is represented by several labels and textboxes. I've also added a button with the following code:

_context.SaveChanges();

When I'm editing data, the changes in whichever textbox has focus are not committed back to the DB. Everything else commits just fine. If I shift focus to another element prior to hitting the save button, it commits as well. I've experienced the same thing with the DataGrid.

I know I'm missing something simple, but I can figure it out. Any ideas on what I'm missing?

Thanks!

+4  A: 

This is because TextBox's default Binding UpdateSourceTrigger is LostFocus. If you modify all your Bindings to set this to PropertyChanged, it will work like you expect:

<TextBox Text="{Binding SomeProperty, UpdateSourceTrigger=PropertyChanged}" />
Abe Heidebrecht
Why doesn't the TextBox "lose focus" when the button is clicked? Can you programatically force this?
Rob Fonseca-Ensor
+1 That is exactly what I was looking for. Thanks!
John L.