c# - 从 String 转换为 Enum 返回在 WPF 中无效的转换

标签 c# .net wpf enums

<分区>

我试图从 WPF 组合框选择的值转换为枚举器,它在运行时返回无效转换,否则字符串和枚举名称匹配我的代码是

Siren.PfundMemberWebServices.Emirates EM = (Siren.PfundMemberWebServices.Emirates)cmbemirate.SelectedValue

最佳答案

要将字符串转换为 enum,您需要使用 Enum.Parse

Siren.PfundMemberWebServices.Emirates EM = (Siren.PfundMemberWebServices.Emirates)Enum.Parse(typeof(Siren.PfundMemberWebServices.Emirates), cmbemirate.SelectedValue);

关于c# - 从 String 转换为 Enum 返回在 WPF 中无效的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234112/

相关文章:

c# - LINQ 查询获取每个其他值的最早条目

c# - 以编程方式删除 XP/Vista/7 中的 TCP/IP 限制

.net - 为什么 EntityCollection 有时会公开扩展方法,有时则不会?

c# - 获取鼠标指针下方的窗口句柄,同时忽略半透明窗口

c# - wpf mvvm 绑定(bind)到子 viewmodel.property

c# - 如何在 C# winform 应用程序中提取包含多个文件夹并覆盖的 rar 文件

c# - 将值插入选定列的问题

c# - 仅在后台操作较长时显示进度

c# - 更改选定颜色列表框

c# - ListView 中是否有针对空值的特殊模板或语法?