This is my Enum
code:
public enum EmployeeType
{
Manager,
Worker
}
I will initialize ComboBox
values whil
EmployeeType selected = (EmployeeType)combobox1.SelectedItem;
You might want to check for null (no selection) first though.
For completeness, here was the sample program I set up. The XAML:
and the code-behind:
using System;
using System.Windows;
namespace WpfApplication1
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
_ComboBox.ItemsSource = Enum.GetValues(typeof(Whatever));
}
public enum Whatever
{
One,
Two,
Three,
Four
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (_ComboBox.SelectedItem == null)
{
MessageBox.Show("No Selection");
}
else
{
Whatever whatever = (Whatever)_ComboBox.SelectedItem;
MessageBox.Show(whatever.ToString());
}
}
}
}