wpf 将枚举与 ObjectDataProvider 绑定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17084180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bind enum with ObjectDataProvider
提问by Hodaya Shalom
I have an enum that bind to a ComboBoxin my view.
ComboBox在我看来,我有一个绑定到 a 的枚举。
public enum MyItems
{
[Browsable(false)]
Item1,
[Browsable(true)]
Item2,
[Browsable(false)]
Item3,
[Browsable(true)]
Item4,
}
In view I use ObjectDataProvider
鉴于我使用 ObjectDataProvider
<ObjectDataProvider x:Key="eMyItems" MethodName="GetValues"
ObjectType="{x:Type System:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="Enums:MyItems"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>:
My ComboBox look like this:
我的组合框看起来像这样:
<ComboBox ItemsSource="{Binding Source={StaticResource eMyItems}}" SelectedValue="{Binding Item}"/>
The problem is that I see all the Enumeven the ones that above them have [Browsable(false)].
问题是我看到了所有的 Enum甚至是它们上面的那些 [Browsable(false)]。


What am I missing?
我错过了什么?
采纳答案by Richard E
One of the answers in this related question looks like it might be of help to you:
这个相关问题的答案之一看起来可能对您有帮助:
WPF Data binding: How to data bind an enum to combo box using XAML?

