How to set comboboxitem silverlight value in xaml
I create a datatemplate for combobox as follows:
<DataTemplate x:Key="AircraftTypeTemplate"> <StackPanel Orientation="Horizontal" Width="340"> <ComboBox> <ComboBoxItem>CJ1</ComboBoxItem> <ComboBoxItem>CJ3</ComboBoxItem> <ComboBoxItem>Bravo</ComboBoxItem> <ComboBoxItem>Excel</ComboBoxItem> <ComboBoxItem>Sovereign</ComboBoxItem> </ComboBox> </StackPanel> </DataTemplate>
It displays fine, but I would like to be able to associate a value with each of the elements without having to bind it to some data context. For example, I would like the CJ1 comboboxitem to have a value of 5. How would I install them in XAML?
how
<ComboBoxItem Value="5">CJ1</ComboBoxItem>
Thanks!
+4
1 answer
You can set an arbitrary string for the Name
property and use it. For more flexibility, you can use the Tag
property, which according to MSDN:
Gets or sets an arbitrary value for an object that can be used to store user information about this object.
Read more about Tag
here . I would say that Tag
is probably better, unlike bending Name
as you wish, and you can insert a string in Tag
as easily as Name
.
+10