1

I have a WPF window with several text box controls using bindings. When I make a change to a text box control and click on the red Close button on the title bar of the window, my bindings are not updated.

I know this because I have an override for the OnClosing method. I check to see if any property has changed and give the user an option to save changes before the window is closed. When this button is clicked, even if I just made a change to a text box, the bound property does not register that it has been changed.

So how do I make sure all "bound" values are updated when I click on the red Close button?

3
  • Why are they not updating before that? Commented May 20, 2014 at 20:53
  • Are there any binding errors in the output window? Your bindings should update automatically. Commented May 20, 2014 at 20:59
  • @Dan I believe the default behavior is for the binding to update once the control loses focus. So it should be bound long before you click the Close button. Commented May 20, 2014 at 21:10

1 Answer 1

1

Assuming your properties used in binding are implementing some type of change notification they should be updated when you click on close... however, try setting the binding mode to TwoWay and UpdateSourceTrigger to PropertyChanged like this:

<TextBox Text="{Binding SomeProperty, Mode=TwoWay, 
    UpdateSourceTrigger=PropertyChanged}">

If your properties are not updated after setting up binding like that than your problem is with change notification...

Sign up to request clarification or add additional context in comments.

1 Comment

This fixed the problem! The Mode was set to TwoWay. Apparently the bindings update in the LostFocus event, and that event was not firing on the last control edited right before the Close button was clicked. With the UpdateSourceTrigger=PropertyChanged setting, the binding property gets updated when changes are made to the control. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.