I'm thinking if you could check these points:
- Did you use generic type for your
ObservableCollection? Could you please provide your
Departmentclass? Also could you please provide the code of XAML file and how you set up the data-binding?
- Ideally, the
ObservableCollectionshould be initialized as an empty list when you create the instance of the ViewModel. Then you just add or remove elements from the collection.
- Line 12 makes no sense. Not sure why you created a new collection but it is not used after that.
- If you already set the data-binding of the ListView, you could just operate the
ObservableCollection, not assign the
My suggestion is:
Use MVVM pattern and set up the data-binding for ListView controls. You could bind the properties such as
SelectedItem of the ListView.
ObservableCollection is for the
ItemsSource of the ListView. For
SelectedItem, you should have other properties called
SelectedTeacher that implement
INotifyPropertyChanged interface. When you remove items from ListViews, just update the
SelectedTeacher. The UI would be updated automatically.