将枚举数据绑定到复选框 C#
有谁知道如何数据绑定 enum
字段(它是 ORed 基 enum
的组合)? 说我有
MyEnumType
{
e1=0x1,
e2=0x2,
e3=0x4
}
,然后我做
MyEnumType myEnum = MyEnumType.e1 | MyEnumType.e3
然后我想显示一个对话框,可用于设置 myEnum
的值。 现在我有一堆复选框,每个复选框对应于 enum
类型的不同值。 根据检查的内容,我循环浏览它们等等。没有完成数据绑定,一切都是手动的。
Does anyone know how one can data bind enum
field which is a combination of ORed base enum
?
Say I have
MyEnumType
{
e1=0x1,
e2=0x2,
e3=0x4
}
and then I do
MyEnumType myEnum = MyEnumType.e1 | MyEnumType.e3
Then I would like to display a dialog box which can be used to set value of myEnum
.
Right now I have a bunch of checkboxes each of which corresponds to a different value in enum
type.
Depending on what is checked I cycle through them and so on. No data binding done, all is manual.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google 搜索
FlaggedEnumEditor
。这将是一个足够好的例子来理解这个概念。Google for
FlaggedEnumEditor
. It will be a good enough example to understand the concept.我将创建一个辅助类(视图模型):
然后只需将复选框数据绑定到属性即可。
但是,如果我有多个这样的枚举,我会开始寻找不需要我编写这么多代码的解决方案。
I would create a helper class (view model) that:
Then just databind the check boxes to the properties.
However if I had more than one such enum, I would start looking for solution that did not need me to write so much code.