views:

40

answers:

1

I have a ChildWindow (Ok, Cancel buttons) that contains binded controls. I want the behind object to be updated only when pressing the 'OK' button. What's the best way to do it?

+2  A: 

You need to set the UpdateSourceTrigger property of the bindings to Explicit. Then, on clicking OK, you call UpdateSource() on the Binding:

BindingExpression expression = textBox1.GetBindingExpression(TextBox.TextProperty);
expression.UpdateSource();

Or you don't bind the ChildWindow to the original ViewModel but use a temporary and assign its values to the original on OK

Ozan