I have a combobox with about 20 items. I want to associate up to 5 attributes with each ComboBoxItem such as color, price, shipping weight, etc.
I want to store all these attributes in the xaml file and retrieve them when item is selected in C# code.
How best do I do this? Is storing everything in Tag and parse the Tag string the best way? Thanks.
<ComboBoxItem Content="Shirt" Tag="Red;14;2"></ComboBoxItem>
You can store anything in the tag, if you want more type safetry create an object:
But even better yet you should not create the items on your own but just have an items collection and bind/data template it using the
ComboBox.ItemsSourceandItemTemplate, then you can store that with the item.The
ComboBox.SelectedItemwill then directly be such an item with all the attributes you need.