<p>As an example take the following code:</p>

<pre><code>public enum ExampleEnum { FooBar, BarFoo }

public class ExampleClass : INotifyPropertyChanged
{
    private ExampleEnum example;

    public ExampleEnum ExampleProperty 
    { get { return example; } { /* set and notify */; } }
}
</code></pre>

<p>I want a to databind the property ExampleProperty to a ComboBox, so that it shows the options "FooBar" and "BarFoo" and works in mode TwoWay. Optimally I want my ComboBox definition to look something like this:</p>

<pre><code>&lt;ComboBox ItemsSource="What goes here?" SelectedItem="{Binding Path=ExampleProperty}" /&gt;
</code></pre>

<p>Currently I have handlers for the ComboBox.SelectionChanged and ExampleClass.PropertyChanged events installed in my Window where I do the binding manually.</p>

<p>Is there a better or some kind of canonical way? Would you usually use Converters and how would you populate the ComboBox with the right values? I don't even want to get started with i18n right now.</p>

<p><strong>Edit</strong></p>

<p>So one question was answered: How do I populate the ComboBox with the right values.</p>

<p>Retrieve Enum values as a list of strings via an ObjectDataProvider from the static Enum.GetValues method:</p>

<pre><code>&lt;Window.Resources&gt;
    &lt;ObjectDataProvider MethodName="GetValues"
        ObjectType="{x:Type sys:Enum}"
        x:Key="ExampleEnumValues"&gt;
        &lt;ObjectDataProvider.MethodParameters&gt;
            &lt;x:Type TypeName="ExampleEnum" /&gt;
        &lt;/ObjectDataProvider.MethodParameters&gt;
    &lt;/ObjectDataProvider&gt;
&lt;/Window.Resources&gt;
</code></pre>

<p>This I can use as an ItemsSource for my ComboBox:</p>

<pre><code>&lt;ComboBox ItemsSource="{Binding Source={StaticResource ExampleEnumValues}}"/&gt;
</code></pre>

[{'answer_id': 58766, 'author': 'rudigrobler', 'author_id': 5147, 'author_profile': 'https://Stackoverflow.com/users/5147', 'pm_score': 5, 'selected': False, 'text': '<p>I don\'t know if it is possible in XAML-only but try the following:</p>\n\n<p>Give your ComboBox a name so you can access it in the codebehind: "typesComboBox1"</p>\n\n<p>Now try the following</p>\n\n<pre><code>typesComboBox1.ItemsSource = Enum.GetValues(typeof(ExampleEnum));\n</code></pre>\n'}, {'answer_id': 58819, 'author': 'rudigrobler', 'author_id': 5147, 'author_profile': 'https://Stackoverflow.com/users/5147', 'pm_score': 0, 'selected': False, 'text': '<p>Try using </p>\n\n<pre><code>&lt;ComboBox ItemsSource="{Binding Source={StaticResource ExampleEnumValues}}"\n    SelectedValue="{Binding Path=ExampleProperty}" /&gt;\n</code></pre>\n'}, {'answer_id': 74011, 'author': 'Greg', 'author_id': 11013, 'author_profile': 'https://Stackoverflow.com/users/11013', 'pm_score': 3, 'selected': False, 'text': '<p>you can consider something like that:</p>\n\n<ol>\n<li><p>define a style for textblock, or any other control you want to use to display your enum:</p>\n\n<pre><code>&lt;Style x:Key="enumStyle" TargetType="{x:Type TextBlock}"&gt;\n    &lt;Setter Property="Text" Value="&amp;lt;NULL&amp;gt;"/&gt;\n    &lt;Style.Triggers&gt;\n        &lt;Trigger Property="Tag"&gt;\n            &lt;Trigger.Value&gt;\n                &lt;proj:YourEnum&gt;Value1&lt;proj:YourEnum&gt;\n            &lt;/Trigger.Value&gt;\n            &lt;Setter Property="Text" Value="{DynamicResource yourFriendlyValue1}"/&gt;\n        &lt;/Trigger&gt;\n        &lt;!-- add more triggers here to reflect your enum --&gt;\n    &lt;/Style.Triggers&gt;\n&lt;/Style&gt;\n</code></pre></li>\n<li><p>define your style for ComboBoxItem</p>\n\n<pre><code>&lt;Style TargetType="{x:Type ComboBoxItem}"&gt;\n    &lt;Setter Property="ContentTemplate"&gt;\n        &lt;Setter.Value&gt;\n            &lt;DataTemplate&gt;\n                &lt;TextBlock Tag="{Binding}" Style="{StaticResource enumStyle}"/&gt;\n            &lt;/DataTemplate&gt;\n        &lt;/Setter.Value&gt;\n    &lt;/Setter&gt;\n&lt;/Style&gt;\n</code></pre></li>\n<li><p>add a combobox and load it with your enum values:</p>\n\n<pre><code>&lt;ComboBox SelectedValue="{Binding Path=your property goes here}" SelectedValuePath="Content"&gt;\n    &lt;ComboBox.Items&gt;\n        &lt;ComboBoxItem&gt;\n            &lt;proj:YourEnum&gt;Value1&lt;/proj:YourEnum&gt;\n        &lt;/ComboBoxItem&gt;\n    &lt;/ComboBox.Items&gt;\n&lt;/ComboBox&gt;\n</code></pre></li>\n</ol>\n\n<p>if your enum is large, you can of course do the same in code, sparing a lot of typing. \ni like that approach, since it makes localization easy - you define all the templates once, and then, you only update your string resource files.</p>\n'}, {'answer_id': 4398752, 'author': 'Gregor Slavec', 'author_id': 355257, 'author_profile': 'https://Stackoverflow.com/users/355257', 'pm_score': 8, 'selected': False, 'text': "<p>You can create a custom markup extension.</p>\n<p>Example of usage:</p>\n<pre><code>enum Status\n{\n    [Description(&quot;Available.&quot;)]\n    Available,\n    [Description(&quot;Not here right now.&quot;)]\n    Away,\n    [Description(&quot;I don't have time right now.&quot;)]\n    Busy\n}\n</code></pre>\n<p>At the top of your XAML:</p>\n<pre><code>    xmlns:my=&quot;clr-namespace:namespace_to_enumeration_extension_class\n</code></pre>\n<p>and then...</p>\n<pre><code>&lt;ComboBox \n    ItemsSource=&quot;{Binding Source={my:Enumeration {x:Type my:Status}}}&quot; \n    DisplayMemberPath=&quot;Description&quot; \n    SelectedValue=&quot;{Binding CurrentStatus}&quot;  \n    SelectedValuePath=&quot;Value&quot;  /&gt; \n</code></pre>\n<p>And the implementation...</p>\n<pre><code>public class EnumerationExtension : MarkupExtension\n  {\n    private Type _enumType;\n\n\n    public EnumerationExtension(Type enumType)\n    {\n      if (enumType == null)\n        throw new ArgumentNullException(&quot;enumType&quot;);\n\n      EnumType = enumType;\n    }\n\n    public Type EnumType\n    {\n      get { return _enumType; }\n      private set\n      {\n        if (_enumType == value)\n          return;\n\n        var enumType = Nullable.GetUnderlyingType(value) ?? value;\n\n        if (enumType.IsEnum == false)\n          throw new ArgumentException(&quot;Type must be an Enum.&quot;);\n\n        _enumType = value;\n      }\n    }\n\n    public override object ProvideValue(IServiceProvider serviceProvider) // or IXamlServiceProvider for UWP and WinUI\n    {\n      var enumValues = Enum.GetValues(EnumType);\n\n      return (\n        from object enumValue in enumValues\n        select new EnumerationMember{\n          Value = enumValue,\n          Description = GetDescription(enumValue)\n        }).ToArray();\n    }\n\n    private string GetDescription(object enumValue)\n    {\n      var descriptionAttribute = EnumType\n        .GetField(enumValue.ToString())\n        .GetCustomAttributes(typeof (DescriptionAttribute), false)\n        .FirstOrDefault() as DescriptionAttribute;\n\n\n      return descriptionAttribute != null\n        ? descriptionAttribute.Description\n        : enumValue.ToString();\n    }\n\n    public class EnumerationMember\n    {\n      public string Description { get; set; }\n      public object Value { get; set; }\n    }\n  }\n</code></pre>\n"}, {'answer_id': 5803123, 'author': 'user659130', 'author_id': 659130, 'author_profile': 'https://Stackoverflow.com/users/659130', 'pm_score': 8, 'selected': False, 'text': '<p>In the viewmodel you can have:</p>\n\n<pre><code>public MyEnumType SelectedMyEnumType \n{\n    get { return _selectedMyEnumType; }\n    set { \n            _selectedMyEnumType = value;\n            OnPropertyChanged("SelectedMyEnumType");\n        }\n}\n\npublic IEnumerable&lt;MyEnumType&gt; MyEnumTypeValues\n{\n    get\n    {\n        return Enum.GetValues(typeof(MyEnumType))\n            .Cast&lt;MyEnumType&gt;();\n    }\n}\n</code></pre>\n\n<p>In XAML the <code>ItemSource</code> binds to <code>MyEnumTypeValues</code> and <code>SelectedItem</code> binds to  <code>SelectedMyEnumType</code>.</p>\n\n<pre><code>&lt;ComboBox SelectedItem="{Binding SelectedMyEnumType}" ItemsSource="{Binding MyEnumTypeValues}"&gt;&lt;/ComboBox&gt;\n</code></pre>\n'}, {'answer_id': 7685443, 'author': 'Martin Liversage', 'author_id': 98607, 'author_profile': 'https://Stackoverflow.com/users/98607', 'pm_score': 5, 'selected': False, 'text': '<p>Based on the accepted but now deleted answer provided by <a href="http://www.ageektrapped.com/blog/the-missing-net-7-displaying-enums-in-wpf/">ageektrapped</a> I created a slimmed down version without some of the more advanced features. All the code is included here to allow you to copy-paste it and not get blocked by link-rot.</p>\n\n<p>I use the <code>System.ComponentModel.DescriptionAttribute</code> which really is intended for design time descriptions. If you dislike using this attribute you may create your own but I think using this attribute really gets the job done. If you don\'t use the attribute the name will default to the name of the enum value in code.</p>\n\n<pre><code>public enum ExampleEnum {\n\n  [Description("Foo Bar")]\n  FooBar,\n\n  [Description("Bar Foo")]\n  BarFoo\n\n}\n</code></pre>\n\n<p>Here is the class used as the items source:</p>\n\n<pre><code>public class EnumItemsSource : Collection&lt;String&gt;, IValueConverter {\n\n  Type type;\n\n  IDictionary&lt;Object, Object&gt; valueToNameMap;\n\n  IDictionary&lt;Object, Object&gt; nameToValueMap;\n\n  public Type Type {\n    get { return this.type; }\n    set {\n      if (!value.IsEnum)\n        throw new ArgumentException("Type is not an enum.", "value");\n      this.type = value;\n      Initialize();\n    }\n  }\n\n  public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) {\n    return this.valueToNameMap[value];\n  }\n\n  public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) {\n    return this.nameToValueMap[value];\n  }\n\n  void Initialize() {\n    this.valueToNameMap = this.type\n      .GetFields(BindingFlags.Static | BindingFlags.Public)\n      .ToDictionary(fi =&gt; fi.GetValue(null), GetDescription);\n    this.nameToValueMap = this.valueToNameMap\n      .ToDictionary(kvp =&gt; kvp.Value, kvp =&gt; kvp.Key);\n    Clear();\n    foreach (String name in this.nameToValueMap.Keys)\n      Add(name);\n  }\n\n  static Object GetDescription(FieldInfo fieldInfo) {\n    var descriptionAttribute =\n      (DescriptionAttribute) Attribute.GetCustomAttribute(fieldInfo, typeof(DescriptionAttribute));\n    return descriptionAttribute != null ? descriptionAttribute.Description : fieldInfo.Name;\n  }\n\n}\n</code></pre>\n\n<p>You can use it in XAML like this:</p>\n\n<pre><code>&lt;Windows.Resources&gt;\n  &lt;local:EnumItemsSource\n    x:Key="ExampleEnumItemsSource"\n    Type="{x:Type local:ExampleEnum}"/&gt;\n&lt;/Windows.Resources&gt;\n&lt;ComboBox\n  ItemsSource="{StaticResource ExampleEnumItemsSource}"\n  SelectedValue="{Binding ExampleProperty, Converter={StaticResource ExampleEnumItemsSource}}"/&gt; \n</code></pre>\n'}, {'answer_id': 12415665, 'author': 'CoperNick', 'author_id': 1457197, 'author_profile': 'https://Stackoverflow.com/users/1457197', 'pm_score': 7, 'selected': False, 'text': '<p>I prefer not to use the name of enum in UI. I prefer use different value for user (<code>DisplayMemberPath</code>) and different for value (enum in this case) (<code>SelectedValuePath</code>). Those two values can be packed to <code>KeyValuePair</code> and stored in dictionary.</p>\n\n<p>XAML</p>\n\n<pre><code>&lt;ComboBox Name="fooBarComboBox" \n          ItemsSource="{Binding Path=ExampleEnumsWithCaptions}" \n          DisplayMemberPath="Value" \n          SelectedValuePath="Key"\n          SelectedValue="{Binding Path=ExampleProperty, Mode=TwoWay}" &gt; \n</code></pre>\n\n<p>C#</p>\n\n<pre><code>public Dictionary&lt;ExampleEnum, string&gt; ExampleEnumsWithCaptions { get; } =\n    new Dictionary&lt;ExampleEnum, string&gt;()\n    {\n        {ExampleEnum.FooBar, "Foo Bar"},\n        {ExampleEnum.BarFoo, "Reversed Foo Bar"},\n        //{ExampleEnum.None, "Hidden in UI"},\n    };\n\n\nprivate ExampleEnum example;\npublic ExampleEnum ExampleProperty\n{\n    get { return example; }\n    set { /* set and notify */; }\n}\n</code></pre>\n\n<p>EDIT: Compatible with the MVVM pattern.</p>\n'}, {'answer_id': 14976878, 'author': 'Jack', 'author_id': 794594, 'author_profile': 'https://Stackoverflow.com/users/794594', 'pm_score': 3, 'selected': False, 'text': '<p>Here is a generic solution using a helper method.\nThis can also handle an enum of any underlying type (byte, sbyte, uint, long, etc.)</p>\n\n<p>Helper Method:</p>\n\n<pre><code>static IEnumerable&lt;object&gt; GetEnum&lt;T&gt;() {\n    var type    = typeof(T);\n    var names   = Enum.GetNames(type);\n    var values  = Enum.GetValues(type);\n    var pairs   =\n        Enumerable.Range(0, names.Length)\n        .Select(i =&gt; new {\n                Name    = names.GetValue(i)\n            ,   Value   = values.GetValue(i) })\n        .OrderBy(pair =&gt; pair.Name);\n    return pairs;\n}//method\n</code></pre>\n\n<p>View Model:</p>\n\n<pre><code>public IEnumerable&lt;object&gt; EnumSearchTypes {\n    get {\n        return GetEnum&lt;SearchTypes&gt;();\n    }\n}//property\n</code></pre>\n\n<p>ComboBox:</p>\n\n<pre><code>&lt;ComboBox\n    SelectedValue       ="{Binding SearchType}"\n    ItemsSource         ="{Binding EnumSearchTypes}"\n    DisplayMemberPath   ="Name"\n    SelectedValuePath   ="Value"\n/&gt;\n</code></pre>\n'}, {'answer_id': 28173443, 'author': 'druss', 'author_id': 1246590, 'author_profile': 'https://Stackoverflow.com/users/1246590', 'pm_score': 5, 'selected': False, 'text': '<p>Use ObjectDataProvider:</p>\n\n<pre><code>&lt;ObjectDataProvider x:Key="enumValues"\n   MethodName="GetValues" ObjectType="{x:Type System:Enum}"&gt;\n      &lt;ObjectDataProvider.MethodParameters&gt;\n           &lt;x:Type TypeName="local:ExampleEnum"/&gt;\n      &lt;/ObjectDataProvider.MethodParameters&gt;\n &lt;/ObjectDataProvider&gt;\n</code></pre>\n\n<p>and then bind to static resource:</p>\n\n<pre><code>ItemsSource="{Binding Source={StaticResource enumValues}}"\n</code></pre>\n\n<p>Find this <a href="https://druss.co/2015/01/wpf-binding-itemssource-to-enum/" rel="noreferrer">solution at this blog</a></p>\n'}, {'answer_id': 31142863, 'author': 'Contango', 'author_id': 107409, 'author_profile': 'https://Stackoverflow.com/users/107409', 'pm_score': 1, 'selected': False, 'text': '<p>This is a <code>DevExpress</code> specific answer based on the top-voted answer by <code>Gregor S.</code> (currently it has 128 votes).</p>\n\n<p>This means we can keep the styling consistent across the entire application:</p>\n\n<p><img src="https://i.stack.imgur.com/khGqs.png" alt="enter image description here"></p>\n\n<p>Unfortunately, the original answer doesn\'t work with a <code>ComboBoxEdit</code> from DevExpress without some modifications.</p>\n\n<p>First, the XAML for the <code>ComboBoxEdit</code>:</p>\n\n<pre><code>&lt;dxe:ComboBoxEdit ItemsSource="{Binding Source={xamlExtensions:XamlExtensionEnumDropdown {x:myEnum:EnumFilter}}}"\n    SelectedItem="{Binding BrokerOrderBookingFilterSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"\n    DisplayMember="Description"\n    MinWidth="144" Margin="5" \n    HorizontalAlignment="Left"\n    IsTextEditable="False"\n    ValidateOnTextInput="False"\n    AutoComplete="False"\n    IncrementalFiltering="True"\n    FilterCondition="Like"\n    ImmediatePopup="True"/&gt;\n</code></pre>\n\n<p>Needsless to say, you will need to point <code>xamlExtensions</code> at the namespace that contains the XAML extension class (which is defined below):</p>\n\n<pre><code>xmlns:xamlExtensions="clr-namespace:XamlExtensions"\n</code></pre>\n\n<p>And we have to point <code>myEnum</code> at the namespace that contains the enum:</p>\n\n<pre><code>xmlns:myEnum="clr-namespace:MyNamespace"\n</code></pre>\n\n<p>Then, the enum:</p>\n\n<pre><code>namespace MyNamespace\n{\n    public enum EnumFilter\n    {\n        [Description("Free as a bird")]\n        Free = 0,\n\n        [Description("I\'m Somewhat Busy")]\n        SomewhatBusy = 1,\n\n        [Description("I\'m Really Busy")]\n        ReallyBusy = 2\n    }\n}\n</code></pre>\n\n<p>The problem in with the XAML is that we can\'t use <code>SelectedItemValue</code>, as this throws an error as the setter is unaccessable (bit of an oversight on your part, <code>DevExpress</code>). So we have to modify our <code>ViewModel</code> to obtain the value directly from the object:</p>\n\n<pre><code>private EnumFilter _filterSelected = EnumFilter.All;\npublic object FilterSelected\n{\n    get\n    {\n        return (EnumFilter)_filterSelected;\n    }\n    set\n    {\n        var x = (XamlExtensionEnumDropdown.EnumerationMember)value;\n        if (x != null)\n        {\n            _filterSelected = (EnumFilter)x.Value;\n        }\n        OnPropertyChanged("FilterSelected");\n    }\n}\n</code></pre>\n\n<p>For completeness, here is the XAML extension from the original answer (slightly renamed):</p>\n\n<pre><code>namespace XamlExtensions\n{\n    /// &lt;summary&gt;\n    ///     Intent: XAML markup extension to add support for enums into any dropdown box, see http://bit.ly/1g70oJy. We can name the items in the\n    ///     dropdown box by using the [Description] attribute on the enum values.\n    /// &lt;/summary&gt;\n    public class XamlExtensionEnumDropdown : MarkupExtension\n    {\n        private Type _enumType;\n\n\n        public XamlExtensionEnumDropdown(Type enumType)\n        {\n            if (enumType == null)\n            {\n                throw new ArgumentNullException("enumType");\n            }\n\n            EnumType = enumType;\n        }\n\n        public Type EnumType\n        {\n            get { return _enumType; }\n            private set\n            {\n                if (_enumType == value)\n                {\n                    return;\n                }\n\n                var enumType = Nullable.GetUnderlyingType(value) ?? value;\n\n                if (enumType.IsEnum == false)\n                {\n                    throw new ArgumentException("Type must be an Enum.");\n                }\n\n                _enumType = value;\n            }\n        }\n\n        public override object ProvideValue(IServiceProvider serviceProvider)\n        {\n            var enumValues = Enum.GetValues(EnumType);\n\n            return (\n                from object enumValue in enumValues\n                select new EnumerationMember\n                       {\n                           Value = enumValue,\n                           Description = GetDescription(enumValue)\n                       }).ToArray();\n        }\n\n        private string GetDescription(object enumValue)\n        {\n            var descriptionAttribute = EnumType\n                .GetField(enumValue.ToString())\n                .GetCustomAttributes(typeof (DescriptionAttribute), false)\n                .FirstOrDefault() as DescriptionAttribute;\n\n\n            return descriptionAttribute != null\n                ? descriptionAttribute.Description\n                : enumValue.ToString();\n        }\n\n        #region Nested type: EnumerationMember\n        public class EnumerationMember\n        {\n            public string Description { get; set; }\n            public object Value { get; set; }\n        }\n        #endregion\n    }\n}\n</code></pre>\n\n<p><em>Disclaimer: I have no affiliation with DevExpress. Telerik is also a great library.</em></p>\n'}, {'answer_id': 40537502, 'author': 'LawMan', 'author_id': 2574087, 'author_profile': 'https://Stackoverflow.com/users/2574087', 'pm_score': 0, 'selected': False, 'text': '<p>I\'ve created an open source <a href="https://toastspopuphelpballoon.codeplex.com/" rel="nofollow noreferrer">CodePlex</a> project that does this.  You can download the NuGet package from <a href="https://www.nuget.org/packages/Mantin.Controls.Wpf.EnumComboBox" rel="nofollow noreferrer">here</a>.</p>\n\n<pre><code>&lt;enumComboBox:EnumComboBox EnumType="{x:Type demoApplication:Status}" SelectedValue="{Binding Status}" /&gt;\n</code></pre>\n'}, {'answer_id': 43624661, 'author': 'MotKohn', 'author_id': 5976576, 'author_profile': 'https://Stackoverflow.com/users/5976576', 'pm_score': 2, 'selected': False, 'text': '<p>If you are using a MVVM, based on @rudigrobler answer you can do the following:</p>\n\n<p>Add the following property to the <strong>ViewModel</strong> class</p>\n\n<pre><code>public Array ExampleEnumValues =&gt; Enum.GetValues(typeof(ExampleEnum));\n</code></pre>\n\n<p>Then in the XAML do the following:</p>\n\n<pre><code>&lt;ComboBox ItemsSource="{Binding ExampleEnumValues}" ... /&gt;\n</code></pre>\n'}, {'answer_id': 45089218, 'author': 'Nick', 'author_id': 862495, 'author_profile': 'https://Stackoverflow.com/users/862495', 'pm_score': 3, 'selected': False, 'text': '<p>My favorite way to do this is with a <code>ValueConverter</code> so that the ItemsSource and SelectedValue both bind to the same property. This requires <strong>no additional properties</strong> to keep your ViewModel nice and clean.</p>\n\n<pre><code>&lt;ComboBox ItemsSource="{Binding Path=ExampleProperty, Converter={x:EnumToCollectionConverter}, Mode=OneTime}"\n          SelectedValuePath="Value"\n          DisplayMemberPath="Description"\n          SelectedValue="{Binding Path=ExampleProperty}" /&gt;\n</code></pre>\n\n<p>And the definition of the Converter:</p>\n\n<pre><code>public static class EnumHelper\n{\n  public static string Description(this Enum e)\n  {\n    return (e.GetType()\n             .GetField(e.ToString())\n             .GetCustomAttributes(typeof(DescriptionAttribute), false)\n             .FirstOrDefault() as DescriptionAttribute)?.Description ?? e.ToString();\n  }\n}\n\n[ValueConversion(typeof(Enum), typeof(IEnumerable&lt;ValueDescription&gt;))]\npublic class EnumToCollectionConverter : MarkupExtension, IValueConverter\n{\n  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n  {\n    return Enum.GetValues(value.GetType())\n               .Cast&lt;Enum&gt;()\n               .Select(e =&gt; new ValueDescription() { Value = e, Description = e.Description()})\n               .ToList();\n  }\n  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\n  {\n    return null;\n  }\n  public override object ProvideValue(IServiceProvider serviceProvider)\n  {\n    return this;\n  }\n}\n</code></pre>\n\n<p>This converter will work with any enum. <code>ValueDescription</code> is just a simple class with a <code>Value</code> property and a <code>Description</code> property. You could just as easily use a <code>Tuple</code> with <code>Item1</code> and <code>Item2</code>, or a <code>KeyValuePair</code> with <code>Key</code> and <code>Value</code> instead of Value and Description or any other class of your choice as long as it has can hold an enum value and string description of that enum value.</p>\n'}, {'answer_id': 65741894, 'author': 'proa', 'author_id': 7564013, 'author_profile': 'https://Stackoverflow.com/users/7564013', 'pm_score': 1, 'selected': False, 'text': '<p>Code</p>\n<pre><code>    public enum RULE\n    {\n        [Description( &quot;Любые, без ограничений&quot; )]\n        any,\n        [Description( &quot;Любые если будет три в ряд&quot; )]\n        anyThree,\n        [Description( &quot;Соседние, без ограничений&quot; )]\n        nearAny,\n        [Description( &quot;Соседние если будет три в ряд&quot; )]\n        nearThree\n    }\n\n    class ExtendRULE\n    {\n        public static object Values\n        {\n            get\n            {\n                List&lt;object&gt; list = new List&lt;object&gt;();\n                foreach( RULE rule in Enum.GetValues( typeof( RULE ) ) )\n                {\n                    string desc = rule.GetType().GetMember( rule.ToString() )[0].GetCustomAttribute&lt;DescriptionAttribute&gt;().Description;\n                    list.Add( new { value = rule, desc = desc } );\n                }\n                return list;\n            }\n        }\n    }\n</code></pre>\n<p>XAML</p>\n<pre><code>&lt;StackPanel&gt;\n   &lt;ListBox ItemsSource= &quot;{Binding Source={x:Static model:ExtendRULE.Values}}&quot; DisplayMemberPath=&quot;desc&quot; SelectedValuePath=&quot;value&quot; SelectedValue=&quot;{Binding SelectedRule}&quot;/&gt;\n   &lt;ComboBox ItemsSource=&quot;{Binding Source={x:Static model:ExtendRULE.Values}}&quot; DisplayMemberPath=&quot;desc&quot; SelectedValuePath=&quot;value&quot; SelectedValue=&quot;{Binding SelectedRule}&quot;/&gt;                        \n&lt;/StackPanel&gt;\n</code></pre>\n'}, {'answer_id': 70387321, 'author': 'BionicCode', 'author_id': 3141792, 'author_profile': 'https://Stackoverflow.com/users/3141792', 'pm_score': 1, 'selected': False, 'text': '<p>It\'s a pain to see all to see how certain overly complicated solutions become a &quot;standard (anti-)pattern&quot; for the most trivial problems: the overhead and complexity of implementing a <code>MarkupExtension</code> and especially decorating enum values with attributes should be avoided. Simply implement a data model.</p>\n<p>Generally, displaying the enumeration value names to the user is a bad idea.  Enumerations are not meant to be displayed in the UI. They are constants that are used in a programmatic context. The value names are not meant for display. They are meant to address the engineer, hence the names usually use special semantics and vocabulary, same as scientific vocabulary is not meant to be understood by the public. Don\'t hesitate to create a dedicated source for the displayed values.</p>\n<p>The problem becomes more evident when localization gets involved.<br />\nThat\'s why all posted answers are simply over engeineered. They make a very simple problem look like a critical issue.<br />\nIt\'s a fact that the most trivial solution is the best. The subject of the original question is most definitely <em>not</em> an exception.<br />\nI highly recommend against any of the provided answers. Although they may work, they add unnecessary complexity to a trivial problem.</p>\n<p>Note, that you can always convert an enum to a list of its values or value names by calling the static <a href="https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues?view=net-6.0#System_Enum_GetValues_System_Type_" rel="nofollow noreferrer"><code>Enum.GetValues</code></a> or <a href="https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames?view=net-6.0" rel="nofollow noreferrer"><code>Enum.GetNames</code></a>, which both return an <code>IEnumerable</code> that you can directly assign to the <code>ComboBox.ItemsSource</code> property e.g.,via data binding.</p>\n<pre class="lang-cs prettyprint-override"><code>IEnumerable&lt;ExampleEnum&gt; values = Enum.GetValues&lt;ExampleEnum&gt;();\nIEnumerable&lt;string&gt; names = Enum.GetNames&lt;ExampleEnum&gt;();\n</code></pre>\n<p>Usually, when defining an enumeration, you don\'t have UI in mind.<br />\nEnumeration value names are not chosen based on UI design rules.<br />\nUsually, UI labels and text in general are created by people with no developer or programmer background. They usually provide all the required translations to localize the application.<br />\nThere are many good reasons not to mix UI with the application.<br />\nYou would never design a class and name its properties with UI (e.g., <code>DataGrid</code> columns) in mind. You may want your column header to contain whitespaces etc.<br />\nSame reason why exception messages are directed at developers and not users.   You definitely don\'t want to decorate every property, every exception, enum or whatever data type or member with attributes in order to provide a display name that makes sense to the user in a particular UI context.<br />\nYou don\'t want to have UI design bleed into your code base and polute your classes.<br />\nApplication and its user interface - this are two different problems.<br />\nAdding this abstract or virtual extra layer of separation allows e.g., to add enum values that should not be displayed. Or more general, modify code without having to break or modify the UI.</p>\n<p>Instead of using attributes and implementing loads of additional logic to extract their values (using reflection), you should use a <em>simple</em> <code>IValueConverter</code> or a dedicated class that provides those display values as a binding source.<br />\nStick to the most common pattern and implement a data model for the <code>ComboBox</code> items, where the class has a property of the enum type as member, that helps you to identify the <code>ComboBox.SelectedItem</code> (in case you need the enum value):</p>\n<p><strong>ExampleEnum.cs</strong></p>\n<pre class="lang-cs prettyprint-override"><code>// Define enumeration without minding any UI elements and context\npublic enum ExampleEnum \n{ \n    FooBar = 0, \n    BarFoo \n}\n</code></pre>\n<p><strong>ExampleClass.cs</strong></p>\n<pre class="lang-cs prettyprint-override"><code>// Define readable enum display values in the UI context.\n// Display names can come from a localizable resource.\npublic class BindingSource : INotifyPropertyChanged\n{\n    public BindingSource()\n    {\n        ItemModels = new List&lt;ItemModel&gt; \n        {\n            new ItemModel { Label = &quot;Foo Bar Display&quot;, Value = ExampleEnum.FooBar },\n            new ItemModel { Label = &quot;Bar Foo Display&quot;, Value = ExampleEnum.BarFoo }\n        }\n    }\n\n    public List&lt;ItemModel&gt; ItemModels { get; }\n\n    private ItemModel selectedItemModel;\n    public ItemModel SelectedItemModel { get =&gt; selectedItemModel; =&gt; set and notify; }\n}\n</code></pre>\n<p><strong>ItemModel.cs</strong></p>\n<pre class="lang-cs prettyprint-override"><code>public class ItemModel\n{   \n    public string Label { get; set; }\n    public ExampleEnum Value { get; set; }\n}\n</code></pre>\n<p><strong>MainWindow.xaml</strong></p>\n<pre class="lang-xml prettyprint-override"><code>&lt;Window&gt;\n  &lt;Window.DataContext&gt;\n    &lt;BindingSource /&gt;\n  &lt;/Window.DataContext&gt;\n\n  &lt;ComboBox ItemsSource=&quot;{Binding ItemModels}&quot;\n            DisplayMemberName=&quot;DisplayValue&quot;\n            SelectedItem=&quot;{Binding SelectedItemModel}&quot; /&gt;\n&lt;/Window&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/58743', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1733/']