Learning MVVM for WPF, and need some help understanding multi-ViewModel scenarios...
So I can think of 20 ways to brute force this, but I'm trying to learn and abide by proper MVVM design.
I am developing an application for managing some data in a SQL Server database. I've got a model structure built around the data it's going to manage from the SQL database. Conceptually I'm planning to build multiple Views to manage the different cascading pieces (it's sort of your typical employee data management scenario, so you've got programs -> employees -> individual roles the employee has had in the company, etc.)
At this point I've got an intro view built with a viewmodel. I'm at the point where I need to manage actually connecting to the database, which'll require a login screen of some kind. All the LOGIC of connecting and collecting data is built into the Model, so I just need to create a VM to fill in the username/password. I guess my core confusion is... I get that Views "own" their ViewModel, and ViewModels "own" their Model, but if I have an application that starts with a particular View/ViewModel, what is it that manages creating and showing other views? Does a ViewModel recognize, say, the Model isn't connected to the DB, and create a Login ViewModel that then somehow uses something to get its View and display it? I've read about ViewModelLocators, but my confusion there is that it feels like it's putting a lot of the logic of the application in a View for it to go create other Views, and that seems like something the ViewModel should do.
I read someone suggesting a sort of "parent" ViewModel that creates other ViewModels as needed, but again how do those VM's know what view to show, or how does that whole thing happen?
I'm a little stuck!
0 comments:
Post a Comment