将 Enum[] 绑定到 ListBox
我有下一个枚举
Enum rcCategory
{
Incoming,
Internal,
Outgoing
}
,并且我的类中有 rcCategory[] 类型的属性“类别”。
我想将此属性绑定到列表框。我为此使用下一个代码
MyListBox.SetBinding (ListBox.ItemsSource, new Binding {Source= myClass.categories});
但是该代码无法按预期工作。 我怎样才能做到这一点。我的列表框始终为空,但源属性具有值
I have next enumeration
Enum rcCategory
{
Incoming,
Internal,
Outgoing
}
and I have property "categories" in my class which has rcCategory[] type.
I would like to bind this property to the listBox. I use next code for this
MyListBox.SetBinding (ListBox.ItemsSource, new Binding {Source= myClass.categories});
But this code doesnt work as expected.
How Can I do this. My listBox always is empty but source property has value
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 Bea Stollnitz 排名最高的文章。
简而言之,您需要绑定到调用静态方法 Enum.GetValues( typeof(YourEnum) ) 的 ObjectProvider 来返回列表。
http://bea.stollnitz.com/blog/?p=28
更新:抱歉,我遇到了一个轻微的速读问题。这个更容易..已验证它是否有效。推荐:查找《ProgrammingWPF》的副本并阅读“数据绑定”一章...
XAML:
代码隐藏:
See Bea Stollnitz top ranked article on it.
In short you need to bind to an ObjectProvider which calls the static method Enum.GetValues( typeof(YourEnum) ) to return the list.
http://bea.stollnitz.com/blog/?p=28
Update: Sorry got a slight speedreading issue. This one is easier.. Verified that it works. Recommended: Find up a copy of ProgrammingWPF and go thru the DataBinding chapter...
XAML:
Codebehind: