Click here to Skip to main content
15,121,564 members

Comments by Издислав Издиславов (Top 2 by date)

I see. There are few approaches and I would suggest starting from the simplest one. You have two controls and two view models, a view model for each UI control. Let's say you have a window and you load one of the controls in it, for example StudentsView, set its view model -bigStudentViewModel, and do some stuffs, then you load the other - CourcesView,one etc. Once you load the second control, the first one and it's view model are to be disposed (I mean marked for Garbage collection) So, first question - can those two view models be combined into one? So, you will still have StudentsView and CourcesView, but you will have one big view model, BigStudentCoursesViewModel. This big view model will always be bound to window and you will change only the view, or you can have both views in one window talking to the same view model. In such case updates will work. Even if you add Teachers and Class Rooms etc etc. the big view model will hold. But if you continue to add more and more stuffs, at one point it will become too big and clumsy. So you have to think of other means to do the job :)
Hello, I have looked (for a short time) at your question and at stack overflow post. Here is my suggestion:
1. (optional)Place ViewModelBase and RelayCommand in separate files
2. Create two viewmodels - one for single NodeDetails, the data class you are using, and one for all node details, i.e. the collection you are using.
3. In view model for single Node detail, all properties that matter should call NotifyPropertyChanged in their set accessor. Yes, property getter setter for Name, for Size, for DateModified etc. ImageSource is tricky, it might be handled few ways other than this.
4. In view model for all node details, your ObservableCollection should hold not NodeDetail objects, but NodeDetailsViewModel objects. Even better, try to use CollectionViewSource instead of raw ObservableCollection. ObservableCollection is useful for tracking adding and removal of elements, but not their properties. Those properties should be tracked by the single view model.
5. (optional)Decide for yourself whether you want to use commands or to handle the events on button clicks and events from observable collection. Use only one approach, I would suggest the first one.
6. In window constructor try to bind DataContext to the view model for all node details. Then change the binding properties accordingly. ItemsSource bind to Students seems fine, so verify the other bindings, those for single node view model. Make sure it works fine.
Then you can try your original way of setting the context via Access method.