2

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?

Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111
  • possible duplicate of [WPF Data binding: How to data bind an enum to combo box using XAML?](http://stackoverflow.com/questions/4306743/wpf-data-binding-how-to-data-bind-an-enum-to-combo-box-using-xaml) – Alberto Jun 06 '14 at 15:47
  • XAML has no concept of skipping over enums that are marked [Browsable(false)]. The BrowsableAttribute is for interactive Properties windows at design time, nothing more. The other linked SO question merely repurposes it. – Sorensen Jul 10 '17 at 14:14

1 Answers1

1

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?

Community
  • 1
  • 1
Richard E
  • 4,819
  • 1
  • 19
  • 25
  • I saw this answer, I do not know where to use EnumerationManager. I wonder if there is any attr that sat to ObjectDataProvider to refer to browsable. – Hodaya Shalom Jun 13 '13 at 10:22
  • The only change you need to make to your code is the inclusion of EnumerationManager in whichever namespace seems appropriate. And to change the ObjectType in your ObjectDataProvider definition to namespace:EnumerationManager. I don't think there is anyway to do what you want without the helper class to search for the Browsable attribute. – Richard E Jun 13 '13 at 10:38