Warm tip: This article is reproduced from serverfault.com, please click

c#-将UWP ComboBox ItemsSource绑定到Enum

(c# - Bind UWP ComboBox ItemsSource to Enum)

发布于 2016-08-29 15:25:41

可以ObjectDataProvider在WPF应用程序中使用来将枚举的字符串值绑定到ComboBox的ItemsSource,如本问题所示

但是,在UWP应用程序中使用类似的代码段时,ff。显示错误信息:

“ Windows Universal项目不支持ObjectDataProvider。”

在UWP中是否有一个简单的替代方法可以做到这一点?

Questioner
miguelarcilla
Viewed
11
AVK 2016-08-30 00:08:44

以下是我的一个原型中的一个工作示例。

枚举

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

ItemsSource

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

这会将组合框绑定到枚举值。