我想要一个带有代码和定义下拉列表的组合框,但只在文本框部分显示所选项目的定义。 For example, Y-Yes and N-No in the dropdown, and when Y is selected, only display Yes in the textbox.
最佳答案
如果您使用 WPF 来执行此操作,请使用绑定(bind)。
假设您绑定(bind)了一个类的集合:
public class Item
{
public string Key{
get
{
return this.Value[0].ToString();
}
}
public string Value{get;set;}
public override string ToString()
{
return this.Key;
}
}
您可以使用它来显示 Key 和 Value,如图所示
<ComboBox x:Name="cmbList" ItemsSource="{Binding}" Text="{Binding SelectedItem.Value}"></ComboBox>
希望本文能帮助您解决问题。
关于c# - 组合框文本显示与下拉列表中的不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3982239/