WPF: Stopping or reversing a selection change in a list box

data-binding, listbox, wpf

Solution

And to do what Kent Boogaart pointed out, refer to this reply..

How to stop a WPF binding from ignoring the PropertyChanged event that it caused?

Problem

Imagine this: you have a Master-Child window consisting of a list of items (the Master window) and a set of controls where you can edit the currently selected item (the Child Window). The child window has "Apply" and "Cancel" buttons. A user begins editing values. He then changes the selection, before pressing the "Apply" button. Your application displays a message "Apply changes to the current item?", with the buttons being "Yes", "No" and "Cancel". If the user presses "Cancel" then the attempt at changing the current selection should fail. The "CurrentSelection" item is databound. I thought I could deal with this in the "setter" part of the `CurrentSelection` property. If the user selects "Cancel", I simply keep the `CurrentSelection` item as it is, and fire a `PropertyChanged` notification event to tell the form to update back to the old selected item. The control is ignoring this notification event. (Which makes sense, the Control is saying "I know the current selection has changed. I just changed it!") Any ideas how to fix this? In summary, the control tries to change the bound `SelectedItem`, and I want to tell it "No you can't change this selected item right now".

Original source