简体   繁体   中英

WPF Window Close Button

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?

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM