c# - 绑定(bind)到枚举

标签 c# windows-8 windows-runtime

有没有办法将组合框绑定(bind)到枚举,因为没有方法可以获取枚举的所有值?

我的枚举是这样的:

public enum SportName
{
    [Display(Name = "football", Description = "Football")]
    Football,

    [Display(Name = "table-tennis", Description = "Table Tennis")]
    TableTennis

}

我有一个检索属性的方法。 我的问题是如何将这些值绑定(bind)到组合框,组合框应显示每个项目的描述。

对我来说,找到一种遍历枚举并创建某种列表的方法就足够了,但我不知道该怎么做。

最佳答案

尝试使用

Enum.GetNames(typeof(SportName)) // returns string[]

Enum.GetValues(typeof(SportName)) // returns int[]

关于c# - 绑定(bind)到枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15557999/

相关文章:

c++ - Windows 8 下未解析的套接字引用

c# - 在 Windows Phone 8.1 中下拉刷新

c# - 使用 Matrox 命令捕获帧

C# 清理文件名

c# - .NET4.5 将组合框绑定(bind)到字典问题。 WPF

c# - 使用来自后台任务的应用程序 resw 文件

linux - "type"命令在 Git Bash 上未按预期工作

c# - 从流创建 ID2D1Bitmap1 时如何尊重 EXIF 方向

c# - 如何按 FIFO 顺序序列化等待任务

c# - StringWriter.ToString() 处的 OutOfMemoryException