Search code examples
c#comboboxenumsuwpuwp-xaml

Bind UWP ComboBox ItemsSource to Enum


It's possible to use the ObjectDataProvider in a WPF application to bind an enum's string values to a ComboBox's ItemsSource, as evidenced in this question.

However, when using a similar snippet in a UWP application, the ff. error message is displayed:

"ObjectDataProvider is not supported in a Windows Universal project."

Is there a simple alternative to do this in UWP?


Solution

  • Below is a working example from one of my prototypes.

    ENUM

    public enum GetDetails
    {
        test1,
        test2,
        test3,
        test4,
        test5
    }
    

    ItemsSource

    var _enumval = Enum.GetValues(typeof(GetDetails)).Cast<GetDetails>();
    cmbData.ItemsSource = _enumval.ToList();
    

    This will bind combobox to Enum Values.