Bind enum with ObjectDataProvider

Hodaya Shalom picture Hodaya Shalom · Jun 13, 2013 · Viewed 9.2k times · Source

I have an enum that bind to a ComboBox in my view.

public enum MyItems
{
    [Browsable(false)]
    Item1,

    [Browsable(true)]
    Item2,

    [Browsable(false)]
    Item3,

    [Browsable(true)]
    Item4,
}

In view I use ObjectDataProvider

 <ObjectDataProvider x:Key="eMyItems" MethodName="GetValues"
                        ObjectType="{x:Type System:Enum}">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="Enums:MyItems"/>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>:

My ComboBox look like this:

<ComboBox  ItemsSource="{Binding Source={StaticResource eMyItems}}" SelectedValue="{Binding Item}"/>

The problem is that I see all the Enum even the ones that above them have [Browsable(false)].

enter image description here

What am I missing?

Answer

Richard E picture Richard E · Jun 13, 2013

One of the answers in this related question looks like it might be of help to you:

WPF Data binding: How to data bind an enum to combo box using XAML?