Silverlight don't have Enum.GetNames() method. This will be very handy method, that should go inside our utility class. So, I went ahead and created a method using reflection, code snippet below.
public class Enum<T>
{
public static IEnumerable<string> GetNames()
{
var type = typeof(T);
if (!type.IsEnum)
throw new ArgumentException("Type '" + type.Name + "' is not an enum");
return (
from field in type.GetFields(System.Reflection.BindingFlags.Public
| System.Reflection.BindingFlags.Static)
where field.IsLiteral
select field.Name).ToList<string>();
}
}
The static method will returns enumerable string collection. You can bind that to a listbox's itemssource. Say, like
this.listBox1.ItemSource = Enum<Colors>.GetNames();