Wpf combobox binding selecteditem not updating

Rated 4.91/5 based on 503 customer reviews

As you can see from the first examples, manually defining the items of a Combo Box control is easy using XAML, but you will likely soon run into a situation where you need the items to come from some kind of data source, like a database or just an in-memory list.Using WPF data binding and a custom template, we can easily render a list of colors, including a preview of the color: It's actually quite simple: In the Code-behind, I obtain a list of all the colors using a Reflection based approach with the Colors class.The code in the View Model first creates the List, and then creates a Collection View based on that list.

wpf combobox binding selecteditem not updating-73

wpf combobox binding selecteditem not updating-42

wpf combobox binding selecteditem not updating-80

As a lovely little bonus, the Combo Box will automatically try to help the user select an existing value when the user starts typing, as you can see from the next screenshot, where I just started typing "Co": By default, the matching is not case-sensitive but you can make it so by setting the Is Text Search Case Sensitive to True.

The approach I went with uses a Collection View which is a class included with .

NET that encapsulates a list and the concept of a current item as well as supporting the INotify Property Changed interface. I set the Is Sychronized With Current Item to true to allow us to track the current item on the Items Source.

If you don't want this auto complete behavior at all, you can disable it by setting the Is Text Search Enabled to False.

A key part of using the Combo Box control is to be able to read the user selection, and even control it with code.

Leave a Reply