Last active
February 8, 2018 15:26
-
-
Save Amoenus/56a4c286d3f6898b1f34ccf6da6576be to your computer and use it in GitHub Desktop.
NiceEnumDescription Example use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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