将UWP ComboBox ItemsSource绑定到Enum [英] Bind UWP ComboBox ItemsSource to Enum

查看:210
本文介绍了将UWP ComboBox ItemsSource绑定到Enum的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用WPF应用程序中的 ObjectDataProvider 将枚举的字符串值绑定到ComboBox的ItemsSource,如这个问题

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.

然而,当在UWP应用程序中使用类似的片段时,ff。显示错误消息:

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

Windows Universal项目不支持ObjectDataProvider。

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

在UWP中是否有一个简单的替代方法?

Is there a simple alternative to do this in UWP?

推荐答案

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

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.

这篇关于将UWP ComboBox ItemsSource绑定到Enum的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆