设置 ComboBoxItem 的文本和值
我正在尝试以编程方式填充组合框。我正在创建 ComboBoxItems 并希望设置它们的文本(对最终用户可见的文本)和它们的值(用户选择它后我将在后台处理的对象。
但是 ComboBoxItem 似乎只具有一个成员满足这两个要求:同时,这不符合我的需求,因为我想区分文本和值属性,并且希望在没有数据绑定的情况下做到这一点
?当前代码如下所示:
ComboBox comboBox;
ComboBoxItem item = new ComboBoxItem();
item.Content = "First Item";
item.Value = 1; // Does not work, no such member as Value!
comboBox.Items.Add(item);
I'm trying to populate a ComboBox programatically. I am creating ComboBoxItems and would like to set their text (the text that is visible for the end-user) and their value (the object that I will handle in the background after the user has selected it.
However the ComboBoxItem seems to only have one member for these two requirements: the Content variable. At the same time this would not fit my needs as I want to distinguish the text and value properties and want to do this without data binding. Is there some viable solution to achieve this?
My current code looks as follows:
ComboBox comboBox;
ComboBoxItem item = new ComboBoxItem();
item.Content = "First Item";
item.Value = 1; // Does not work, no such member as Value!
comboBox.Items.Add(item);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你可以使用 Tag 属性。
Guess you can use the Tag property.