2009-08-14 26 views

回答

0

使用SelectedItem财产

+0

的SelectedItem给我的类型的机会,但不是价值本身。 它返回我ComboBoxItem,这不是我想要的。 – PlayKid 2009-08-14 12:07:21

+0

它返回ComboBoxItem,因为您将列表中的项目定义为ComboBoxItems ...如果使用ItemsSource属性定义内容,它将返回实际的数据项目。你如何定义ComboBoxItem的“值”? – 2009-08-14 12:29:34

0

你可以结合使用反射用的DisplayMemberPath属性:

var itemType = cbx.SelectedItem.GetType(); 
var pi = itemType.GetProperty(cbx.DisplayMemberPath); 
var stringValue = pi.GetValue(cbx.SelectedItem, null).ToString(); 
相关问题