Wpf combobox itemssource not updating

Recently, I received a question from one of my twitter tribemates on using the Combo Box in WPF with objects, and it centered around the difference between the Selected Value, Selected Value Path, and Selected Item properties.

This post will go through the differences, and how they are used, and also do a little review on databinding in WPF.

If you can't override Equals, then you will have to use the Selected Value/Selected Value Path method for synchronizing the value of the Category Parent to the item in the Category List.

This works as well, but it obviously not nearly as encapsulated as changing the POCOs themselves.

This is not news, as it works very similarly in Win Forms.

What is surprising, is when the selected Product changes, the list doesn't update if you are using an ORM tool (like NHibernate or Castle Active Record).

If we define out Products Combo Box like this (I've eliminated the attached properties and other styling from these samples for readability):(Rember for Text Boxes, the Update Source Trigger default is Lost Focus.

The reason for this is that the Category Parent property holds an instance of a category object wrapped in a proxy (I use lazy initialization), and the Category List holds a set of instances of Category objects.

These end up not being the same in terms of the default object Equals method. Either overload the Equals method in your objects (also remembering to overload Get Hash Code), or use Selected Value and Selected Value Path.

Hmmm, ok, so we're setting the Data Context in the code as well as the XAML. Now we can change the 'The Enum' property via the Combo Box, or indeed via code: my Class. B; for example, and this is displayed correctly in the Combo Box and the property on the my Class instance is correct as well! I have a common object that is used three times,masked as 5 different User Controls (member use varies). Hi Sally, I'm not really sure exactly what you're asking, is it that you want to store the value of the enum in a control, but you want that value to be hidden from the display?

Is there a better *simpler* way to achieve the same goal?? public enum Type Identifier public class Common Object I have a WPF User Control that has a generalized object binding. I just need the object member to be set to Type Identifier. The thing is that I can't directly reference the enum above in my user control project.

Leave a Reply