Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已将枚举列表绑定到组合框。现在我想SelectedItem返回枚举,它当前将它返回为 type object。如何将此对象转换为我的枚举?
SelectedItem
object
我的框架是 windows-phone-7 上的 silverlight
直接投射:
MyEnum selected = (MyEnum)cboCombo.SelectedItem;
请注意,在这种情况下您不能使用as强制转换,因为 anEnum是一种值类型。
as
Enum
你试过这个吗??
YourEnum abc = (YourEnum) Enum.Parse(typeof(YourEnum), yourObject.ToString());