views:

27

answers:

2

Is there a "BeforeSelectionChanged" event for the combobox? I want to verify some stuff before the SelectedItem property changes.

A: 

I don't think that there is, unfortunately.

You might be able to use the PreviewLeftMouseDown event and determine if the mouse is over an item in the ComboBox. If it is over an item that isn't the SelectedItem, you know it is about to change.

Andy
That is an interesting idea, but it sounds like it would be hard to get right.
Jonathan Allen
And you can also need to handle keyboard events...
Thomas Levesque
+1  A: 

There's no PreviewSelectionChanged event. Instead of using two way binding, use one way binding to SelectedItem and get updates through command or SelectionChanged event. That way you can in the handler do some verification and even fake a cancel of the selection.

Wallstreet Programmer
That will work, thanks.
Jonathan Allen