Imagine: you have a Master-Child window, consisting of a list of elements (main window) and a set of controls where you can edit the currently selected element (child window). In the child window there are "Apply" and "Cancel" buttons.
The user begins to edit the values. He then changes the selection before clicking the "Apply" button.
Your application displays the message "Apply changes to the current item?", With the buttons "Yes", "No" and "Cancel". If the user clicks "Cancel", an attempt to change the current selection will fail.
The CurrentSelection element is a data binding.
I thought I could handle this in the "setter" part of the CurrentSelection property. If the user selects "Cancel", I simply save the CurrentSelection element as it is and fire the PropertyChanged notification event to tell the form to return to the old selected element. The control ignores this notification event. (Which makes sense, Control says: "I know that the current selection has changed, I just changed it!")
Any ideas how to fix this? So the control is trying to change the SelectedItem binding, and I want to say "No, you cannot change this selected item right now."
data-binding wpf listbox
Andrew Shepherd
source share