Silverlight组合框下拉列表文本/值
Silverlight combobox中是否有类似于html下拉列表的值和文本?我只看到内容属性。我读到我可以使用tag属性,但在执行以下操作时无法从代码中检索值Silverlight组合框下拉列表文本/值,silverlight,Silverlight,Silverlight combobox中是否有类似于html下拉列表的值和文本?我只看到内容属性。我读到我可以使用tag属性,但在执行以下操作时无法从代码中检索值 mycombobox.Tag.toString(); 有人知道最好的方法吗 谢谢,有一个自定义类,可以保存两个属性来表示下拉项的值和文本字段。并将该类的列表绑定为combobox的ItemsSource 你可以试试 public class CustomComboBoxItem { public int Key { get
mycombobox.Tag.toString();
有人知道最好的方法吗
谢谢,有一个自定义类,可以保存两个属性来表示下拉项的值和文本字段。并将该类的列表绑定为combobox的ItemsSource 你可以试试
public class CustomComboBoxItem
{
public int Key { get; set; }
public string DisplayText { get; set; }
}
及
你说的是
SelectedItem
/SelectedValue
?你可以用字符串填充它,但它基本上不是SL方式,所以我建议使用适当的绑定功能。有很多例子,比如。最好的方法是使用绑定。
public MainPage()
{
InitializeComponent();
myComboboxSource = new List<CustomComboBoxItem>();
myComboboxSource.Add(new CustomComboBoxItem { Key = 1, DisplayText = "First Text" });
myComboboxSource.Add(new CustomComboBoxItem { Key = 2, DisplayText = "Second Text" });
}
public List<CustomComboBoxItem> myComboboxSource { get; set; }
<ComboBox Name="myCombobox" Height="25" Width="200" ItemsSource="{Binding myComboboxSource, ElementName= mainPage}" SelectedValuePath="Key" DisplayMemberPath="DisplayText"/>
<Button Click="Button_Click" Height="25" Width="100" Content="Get Selected Value"/>
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(Convert.ToString(myCombobox.SelectedValue));
}