WPF editable ComboBox binding

Today (and most of my night) I’ve been stuck with trying to bind to an editable WPF combo box. It sounds stupid and it is, really.

The scenario is this: You have an editable combo box to which you bind a list of view models. I specify a data template in order to get the correct binding to a property on the view model. This however, doesn’t display the selected item properly. I specify a ToString() override to solve this and get a value. However when the property that feeds the ToString is updated I get no update. The thing is that the SelectedItemValue and such doesn’t come in to play and certainly doesn’t care about updates to your view model.

So in order to fix this I create a wrapper subclass to the ComboBox class and make it listen to changes to the SelectedItem and trigger an internal update method when needed.

The example, code and fix are all available here: https://github.com/ddikman/ComboBoxBindingExample

combobox binding