views:

108

answers:

2

I have binded a list of enum to a combobox. Now I want to get the SelectedItem return the enum, which currently returns it as type object. How do I convert this object to my enum?

My framework is silverlight on windows-phone-7

+2  A: 

Have you tried this??

YourEnum abc = (YourEnum) Enum.Parse(typeof(YourEnum), yourObject.ToString());
viky
That may work with a string property, but not with `SelectedItem`.
leppie
@leppie: I thought, for some reason, typecasting is not working for OP, so he can try this trick.
viky
+2  A: 

Cast it directly:

MyEnum selected = (MyEnum)cboCombo.SelectedItem;

Note that you can't use the as cast in this case since an Enum is a value type.

Jon Seigel
wow, this works now. For some reason, the compiler was telling me that `MyEnum` is being used as a variable in that exact statement.
Shawn Mclean