gpt4 book ai didi

c# - 组合框文本显示与下拉列表中的不同

转载 作者:行者123 更新时间:2023-11-30 18:43:43 26 4
gpt4 key购买 nike

我想要一个带有代码和定义下拉列表的组合框,但只在文本框部分显示所选项目的定义。 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com