绑定到ComboBox时如何在xaml中排除某些枚举成员? [英] How to exclude some enum members in the xaml when bound to a ComboBox?
问题描述
我正在使用VS 2010,.Net 4.0和C#.在将枚举绑定到ComboBox控件时,我希望能够排除枚举的某些成员.我似乎记得在一段时间的帖子中看到过针对这种功能的解决方案 回来,但我找不到了.
I am using VS 2010, .Net 4.0 and C#. I want to be able to exclude certain members of an enumeration when binding the enumeration to a ComboBox control. I seem to remember seeing a solution to this type of feature in a posting awhile back, but I can no longer find it.
我有一个这样的枚举:
public enum MyEnum
{
First,
Second,
Third,
Fourth,
Fifth
}
我想像这样将枚举绑定到ComboBox上:
I want to bind the enum to a ComboBox like this:
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="MyEnumSelection">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="common:MyEnum"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<ComboBox IsSynchronizedWithCurrentItem="True"
SelectedValue="{Binding Path=MyEnumProperty}"
ItemsSource="{Binding Source={StaticResource MyEnumSelection}}"/>
我似乎还记得,可以通过在ItemsSource绑定代码中添加一些xaml语法来从枚举中排除某些成员.我认为它看起来像这样:
I seem to remember it was possible to exclude certain members from the enum by adding some xaml syntax in the ItemsSource binding code. I think it looked something like this:
<ComboBox IsSynchronizedWithCurrentItem="True"
SelectedValue="{Binding Path=MyEnumProperty}"
ItemsSource="{Binding Source={StaticResource MyEnumSelection}, Exclude="Fifth"}"/>
有人知道这样做的正确语法吗?可以排除的内容是否有限制?
Does anybody know the correct syntax to do this? Are there limitations to what can be excluded?
谢谢,戴夫
戴维研发软件工程师安捷伦技术公司
Dave R&D SW Engineer Agilent Technologies
推荐答案
一个链接:
http://social.msdn.microsoft.com /Forums/en/wpf/thread/53674ea3-34ae-4473-a655-24c52f7d0a75
希望这会有所帮助
在需要帮助时,请记住Google是您的朋友
Remember Google is your friend when needing help
Lloyd Sheen
这篇关于绑定到ComboBox时如何在xaml中排除某些枚举成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!