Skip to content

Instantly share code, notes, and snippets.

@Amoenus
Last active February 8, 2018 15:26
Show Gist options
  • Save Amoenus/56a4c286d3f6898b1f34ccf6da6576be to your computer and use it in GitHub Desktop.
Save Amoenus/56a4c286d3f6898b1f34ccf6da6576be to your computer and use it in GitHub Desktop.
NiceEnumDescription Example use
using System.Collections.Generic;
using System.Windows;
using Amoenus.NiceEnumDescription;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
public MainWindow()
{
InitializeComponent();
ComboBoxEnum.ItemsSource = NiceEnum.GetEnumDescriptionDictionary<Items>(NotExistOption.ToString); //NotExistOption.ToString is a default and can be omitted
ComboBoxEnum.DisplayMemberPath = "Value";
}
private void ComboBoxEnumSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
var selectedItem = (KeyValuePair<Items, string>)ComboBoxEnum.SelectedItem;
Items item = selectedItem.Key;
}
}
enum Items
{
[EnumDescription("One Description")]
One,
[EnumDescription("Two Description")]
Two,
Three
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment