C#-DisplayMemberPath在ComboBox中不起作用

时间:2018-07-24 17:57:19

标签: c# wpf binding

我的对象

public class Object
{
    public string Key;
    public string Value;
}

我可观察的集合:

private ObservableCollection<Object> objects;

public ObservableCollection<Object> Objects
{
        get
        {
            return objects;
        }
        set
        {
            if (value != objects)
            {
                objects = value;
                OnPropertyChanged("Objects");
            }
        }
    }

XAML:

<ComboBox x:Name="objectsMenu" ItemsSource="{Binding Objects, Mode=OneWay}" DisplayMemberPath="Key" />

我似乎无法进入我的ItemsSource项的“ Key”属性,并且ComboBox项为空白。我收到的错误:

BindingExpression path error: 'Key' property not found on 'object' ''Object' (HashCode=64844482)'. BindingExpression:Path=Key; DataItem='Object' (HashCode=64844482); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

也许有人遇到过这个吗?

0 个答案:

没有答案