This is my Enum
code:
public enum EmployeeType
{
Manager,
Worker
}
I will initialize ComboBox
values whil
Actually, if I would had to do that, I would have built an ObservableCollection
previously to the binding (for exemple in the constructor of your view model, using the Enum.GetNames(typeof(EmployeeType))
and then iterating on each values to reparse them as EmployeeType
types.
Once you have your collection set up, you just have to bind it to your ComboBox
and then, when selecting an item, you should retreive a type EmployeeType
without having to parse it.
public class VieModel
{
private ObservableCollection _internal;
public ViewModel()
{
_internal = new ObservableCollection();
var tempList = Enum.GetNames(typeof(EmployeeType));
foreach(var val in tempList)
{
EmployeeType et = Enum.Parse(typeof(EmployeeType),val);
internal.Add(et);
}
}
public ObservableCollection EmployeeTypes
{
get { return _internal; }
}
}
Then set the view model as the data context of your view, and bind your combobox to EmployeeTypes
:
The selected should return an object of type EmployeeType
.
PS: Sorry about code spelling mistakes, I don't have any C# editor near me right now ;)