2

ListBox对象被绑定BindingList<KeyValuePair<string, string>>

在 SelectionChanged 事件上,我需要将所选项目作为KeyValuePair<string, string>

以下代码给出错误,因为 KeyValuePair 不能用作引用类型。

KeyValuePair<string, string> selectedProperty = listProperties.SelectedItem as KeyValuePair<string, string>;

有什么好的解决方法?

4

1 回答 1

9

尝试使用直接转换而不是as

var selectedProperty = (KeyValuePair<string, string>)listProperties.SelectedItem;
于 2011-06-19T19:10:05.213 回答