Tool
Mar 1st, 2010, 10:42 PM
I'm pretty new with WPF and the MVVM Framework, only about a week of playing with both.
The problem I am running into is when binding to a list from my ViewModel. No matter what I do I cannot get the View to update the DataContext when an item is added, removed, or all items are cleared. I've played with the INotifyPropertyChanged while trying to figure out some other problems, but that does not work with collections. I read about INotifyCollectionChanged, but I can't seem to get that to work either.
I wrote a sample project to display the error I am having. When you select an item and remove it, it will display how many items are currently in the list, then remove it, then how many are left. The listbox will not update, but the Refresh Items button will reset the DataContext and it will display properly.
Quick rundown of the project:
MainWindow, has a grid with a slot for my List view, (controller is created in code, then added to that slot in the constructor).
The controller creates an instance of the view.
View has an instance of the ViewModel, binds to the ItemsSource property of the list box.
I created an IListViewItem interface with a Title, Description and ID, to make custom list items.
ListViewItem implements the interface.
MockListData generates 15 items and adds them to the ListViewModel.
Sorry if I just confused anyone. Any help would be appreciated. Also, I am not too familiar with the MVVM Pattern, so if anyone notices I'm doing something completely wrong, feel free to point that out if you'd like.
The problem I am running into is when binding to a list from my ViewModel. No matter what I do I cannot get the View to update the DataContext when an item is added, removed, or all items are cleared. I've played with the INotifyPropertyChanged while trying to figure out some other problems, but that does not work with collections. I read about INotifyCollectionChanged, but I can't seem to get that to work either.
I wrote a sample project to display the error I am having. When you select an item and remove it, it will display how many items are currently in the list, then remove it, then how many are left. The listbox will not update, but the Refresh Items button will reset the DataContext and it will display properly.
Quick rundown of the project:
MainWindow, has a grid with a slot for my List view, (controller is created in code, then added to that slot in the constructor).
The controller creates an instance of the view.
View has an instance of the ViewModel, binds to the ItemsSource property of the list box.
I created an IListViewItem interface with a Title, Description and ID, to make custom list items.
ListViewItem implements the interface.
MockListData generates 15 items and adds them to the ListViewModel.
Sorry if I just confused anyone. Any help would be appreciated. Also, I am not too familiar with the MVVM Pattern, so if anyone notices I'm doing something completely wrong, feel free to point that out if you'd like.