0

I have a simple problem, but I'm unable to figure it out. I just want to use properly a comboBox over an ObservableCollection of objects showing the value of a property inside it. Here my XAML:

<ComboBox ItemsSource="{Binding Path=SavedQueries, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                  DisplayMemberPath="Name"
                  SelectedValuePath="Name"/>

and my code:

public ObservableCollection<SavedQueryObject> SavedQueries
{
    get
    {
        return _savedQueries;
    }
    set
    {
        _savedQueries = value;
        OnPropertyChanged();
    }
}
public HomeViewModel()
{
    LoadQueries();
}
public async void LoadQueries()
{
    Query query = new Query();

    SavedQueries = new ObservableCollection<SavedQueryObject>(query.queryItems());
}

The object SavedQueriesObject contains 3 proprieties and one of them is called 'Name'.

What I get it's just a list of blank fields. I don't think it's a problem of DataContext because I can bind successfully others properties between model and view.

Additional info:

screen

Massimo
  • 205
  • 1
  • 3
  • 10
  • 3
    Please also show the code for `SavedQueriesObject`. – Christoph Fink Feb 06 '18 at 08:38
  • Updated my question. Using 'OnPropertyChanged("SavedQueries") doesn't make any difference. – Massimo Feb 06 '18 at 09:07
  • Note that it is pointless to use an ObservableCollection when you always replace the SavedQueries collection with a new one. It is also pointless to set `Mode=TwoWay` and `UpdateSourceTrigger=PropertyChanged` on the ItemsSource Binding. Both settings have no effect. – Clemens Feb 06 '18 at 09:14
  • 2
    It sounds like your problem is that the `Name` member of the SavedQueryObject class isn't a public property. – Clemens Feb 06 '18 at 09:17
  • @Clemens Good idea! Using the code above and a public property `Name`on `SavedQueryObject` I could not reproduce the issue. – MaSiMan Feb 06 '18 at 09:19
  • SavedQueryObject is inside a .dll and I didn't find any documentation about it. Anyway Clemens is right. My problem is due that fact 'Name' is not a public property. Thank you! – Massimo Feb 06 '18 at 10:32

0 Answers0