15,790,022 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Python questions
View PHP questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Издислав Издиславов (Top 2 by date)
Издислав Издиславов
17-Jan-21 8:16am
View
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 :)
Издислав Издиславов
16-Jan-21 12:34pm
View
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.