0

My object:

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

My observable collection:

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" />

I just cannot seem to get to the "Key" property of my ItemsSource items, and the ComboBox items stand blank. The error I'm getting:

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')

Anyone encountered this before maybe?

Milos
  • 1
  • 1
    `Object` is a base type in .NET. rename your class to avoid this collision. and "'Key' property not found" because Key in your class is not a property, it is a *field*. research their important difference. To make a property add `{get;set;}`. e.g. `public string Key {get;set;}` – ASh Jul 24 '18 at 17:59
  • Thank you, endlessly, I literally spent hours on this thing. I know about the object, I simplified the whole ordeal. – Milos Jul 24 '18 at 18:04
  • Your class should inherit from keyvaluepair – Ctznkane525 Jul 24 '18 at 18:31

0 Answers0