Set the text and value of a ComboBoxItem

combobox, key-value, silverlight

Solution

Guess you can use the Tag property.

Problem

I'm trying to populate a ComboBox programatically. I am creating ComboBoxItems and would like to set their text (the text that is visible for the end-user) and their value (the object that I will handle in the background after the user has selected it. However the ComboBoxItem seems to only have one member for these two requirements: the Content variable. At the same time this would not fit my needs as I want to distinguish the text and value properties and want to do this without data binding. Is there some viable solution to achieve this? My current code looks as follows: ``` ComboBox comboBox; ComboBoxItem item = new ComboBoxItem(); item.Content = "First Item"; item.Value = 1; // Does not work, no such member as Value! comboBox.Items.Add(item); ```

Original source