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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 08:59:36  来源:igfitidea点击:

Bind enum with ObjectDataProvider

wpfmvvmbindingenumsobjectdataprovider

提问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)]

enter image description here

在此处输入图片说明

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?

WPF 数据绑定:如何使用 XAML 将枚举数据绑定到组合框?