I want to bind an ObservableCollection
of model items to an ItemsControl
and be able to manage adding and removing items to and from that collection, as well as synchronize presence of member in the collection with views of user controls that represent those items.
but I realized that when I trying to remove the models, they are still there and the views are still displayed as the last time I added one.
I think my problem is that I can't understand how to manage the ViewModel and View that associated with the model that I trying to remove. do I also have to dereference the model from the ViewModel(or the ViewModel from the View) to let the GC do its work?
do I need to construct the ViewModel or Models in code-behind? or is it enough to declare the DataContext
's type in the XAML, or if both are there it is redundant? (maybe some null reference caused this because there was no reference to remove?)
I'm new to WPF and MVVM and I think that question is pretty basic, but I didn't find any question about that integration of ItemsControl
with ObservableCollection
.