Binding that is easy. The only problem is that the extension method GetNames()
is not available in windows phone. However, you can write one.
public static class EnumExtensions {
public static IEnumerable<string> GetNames<TEnum>() where TEnum : struct {
var type = typeof(TEnum);
if (!type.IsEnum)
throw new ArgumentException(String.Format("Type '{0}' is not an enum", type.Name));
return (
from field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)
where field.IsLiteral
select field.Name)
.ToList<string>();
}
}
Once you have that it is easy to bind it to any list.
public enum MyEnum {
v1, v2, v3
}
// Binding
myListPicker.ItemsSource = EnumExtensions.GetNames<MyEnum>();
// Getting selected value
var myEnum = (MyEnum)Enum.Parse(typeof(MyEnum), myListPicker.SelectedItem.ToString());