如何在xaml中设置silverlight ComboxItem值
我为组合框创建一个datatemplate,如下所示:如何在xaml中设置silverlight ComboxItem值,silverlight,combobox,Silverlight,Combobox,我为组合框创建一个datatemplate,如下所示: <DataTemplate x:Key="AircraftTypeTemplate"> <StackPanel Orientation="Horizontal" Width="340"> <ComboBox> <ComboBoxItem>CJ1</ComboBoxItem> <Comb
<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>
CJ1
CJ3
布拉沃河
擅长
君主的
它呈现得很好,但我希望能够将值与每个项关联起来,而不必将其绑定到某些数据上下文。例如,我希望CJ1 comboboxitem的值为5。我如何在XAML中设置它们
比如:
CJ1
谢谢 您可以将
Name
属性设置为任意字符串并使用该字符串。为了获得更大的灵活性,您可以使用标记
属性,根据MSDN:
获取或设置可用于存储有关此对象的自定义信息的任意对象值
您可以阅读有关标签的更多信息。我想说,
Tag
可能比按照自己的意愿弯曲Name
更好,而且你可以像Name
一样轻松地在Tag
中插入字符串,谢谢!还有一件事:如何将组合框的SelectedValue绑定到标记?没问题。将SelectedValue
绑定到Tag
看起来像
。效果很好-谢谢!
<ComboBoxItem Value="5">CJ1</ComboBoxItem>