Search code examples
c#comboboxenumswindows-8.1mvvm-light

Binding enum to combobox at win8 platform using mvvmlight


I'm trying to bind an enum to combobox, so I tried to follow a guide that suggested using this code:

    <Page.Resources>
    <ObjectDataProvider MethodName="GetValues"
    ObjectType="{x:Type sys:Enum}"
    x:Key="ExampleEnumValues">
        <ObjectDataProvider.MethodParameters>
            <x:Type TypeName="ExampleEnum" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</Page.Resources>

The problem is that it says that "objectdataprovider is not supported in a windows app project". is there another way to do it? Thanks to everyone in advance.


Solution

  • Well, if you want the enum values showed in the combobox, all you have to do is this:

    at your viewModel:

        public Array SomeName { get; set; }
    //c'tor
     public viewModelName()
            {
                SomeName = Enum.GetValues(typeof(MyEnumType));
            }
    

    And at your view:

    <ComboBox ItemsSource="{Binding SomeName}" ></ComboBox>