Given an enum like
public enum MyEnum
{
Red,
Blue,
Green
}
You'd have a class like:
[Serializable]
public class MyEnumList : Csla.NameValueListBase
{
public static MyEnumList GetList()
{
return Csla.DataPortal.Fetch(new Criteria(typeof(MyEnumList)));
}
private MyEnumList()
{ /* require use of factory method */ }
[Csla.RunLocal]
protected override void DataPortal_Fetch(object criteria)
{
this.IsReadOnly = false;
foreach (MyEnum item in Enum.GetValues(typeof(MyEnum)))
Add(new Csla.NameValueListBase.NameValuePair(
item, Enum.GetName(typeof(MyEnum), item)));
this.IsReadOnly = true;
}
}
Then you can bind it like you'd bind any other object/list to a combobox, as long as the object's property is of type MyEnum:
MyEnum _color;
public MyEnum Color
{
get
{
CanReadProperty("Color", true);
return _color;
}
set
{
CanWriteProperty("Color", true);
if (!_color.Equals(value))
{
_color = value;
PropertyHasChanged("Color");
}
}
}
EditHow can I load a NVL object from an enum in Silverlight?
http://forums.lhotka.net/forums/thread/32564.aspxEditHow can I localize the text?
this thread has some good information on localization.