Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the text and value of a ComboBoxItem

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);
like image 217
Gergely Orosz Avatar asked Oct 27 '09 14:10

Gergely Orosz


1 Answers

Guess you can use the Tag property.

like image 63
thomasmartinsen Avatar answered Oct 11 '22 22:10

thomasmartinsen