Search code examples
listxamlmvvmcomboboxbinding

A list That I use doesn't display in a page WPF


I have a list in a model, I use it in a view to add things or remove things in it from a viewmodel. Then, normally I can go to an other page and view the list in a combobox. But now it doesn't show in the ComboBox.

I don't know how to in a way "cast" my list in the combobox.Any help is apprciated !

List Collection in my model Here is my list<> in my model Bibliotheque. List COllection in my first viewModel and here it is in my viewmodel where I add and remove item. Which result in my view:The binding of the list in a listview And here is the problemList Collection in my second viewmodel In my other viewmodel for my other page I recreate the list to use it but then in my view in the combobox :The comboBox that I try to bind my list to. When I add thing in the other page and check if the comboBox changed nothing happen.

I really don't know where it goes wrong...

UPDATE

When I Used a OnpropertyChanged(nameof(Collection)); in one of my fonction in my viewModel ComptesEtudiants I could now see my list. So the problem must be that the list need a refreshing when I go to the page...


Solution

  • Instead of:

    List<Livre>
    

    You should use:

    ObservableCollection<Livre>
    

    The ObservableCollection notifies the UI when you add/remove items.