I had a question about the VM responsibilities when it comes to pop-ups. When an app is popping a message box or some kind of dialog (with MVVM), the two options that we have are:
How do you guys tackle this case?
Don't put the UI code in the VM, that just causes a lot of headaches down the road.
You usually have two cases when you want to pop a window or dialogue. Either you are doing it because of a business case, e.g. a detail view on double clicking a list, or it is completely UI based, e.g. popping an options window. In the first case it's best to use an event in the VM, in the later case I just use an event handler. A good rule of thumb is, if you don't need any (significant) VM variables to accomplish the action then you should just use an event handler.
Above all, use your head and trust your judgment, you'll learn which to use soon enough.
Check out Onyx. This is an M-V-VM library (full disclosure: I'm the author) based on using services and either the Service Locator or Dependency Injection patterns. There's services for MessageBox and common dialogs, and it's pretty easy to add your own services as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With