MVVM approach advice needed

damien.darhk

New member
Joined
Aug 13, 2021
Messages
4
Programming Experience
3-5
Hello,
I'm a beginner in MVVM, and WPF. My boss asked me to port a winform application in WPF; Basically it have an interface with docked windows (like VS), where each window display some data( loaded from a file) in different way: simple chart, tables, 3d chart, raw data ecc(should be 6 window); this are also interactive, I mean the user can change some value and save the file update for other uses.
I'd like to use mvvm pattern (and caliburn micro framework) to do the task.
My problem is that I'm not sure to have correctly understand how to approach an application like this in MVVM.
For my understanding, I need to use for docking something like avalondock(that support mvvm), and create a View(as usercontrol in VS) and a ViewModel for each dockend"window" plus one as container, and a Model that actually contains the file as an array/stream.
I'm also unsure where handle the "interactivity"(basically the mouse change chart value by mouse), because I founded different answers googleing.
I can add more details if needed . Any advice?
 
I'm also unsure where handle the "interactivity"(basically the mouse change chart value by mouse)
In general, in the ViewModel. Only rarely would you do this is the View when are truly affecting GUI stuff and not indirectly updating the underlying model.

Take time to read some of Josh Smith's writings about MVVM to understand how MVVM applications are structured and laid out. His book "Advanced MVVM" is also an excellent read.


It takes a huge mindset change to go from the WinForms way of doing things to the WPF MVVM way of doing things. Some people just give up and end up using WPF the WinForms way. Please don't do this unless you are just writing a toy application to get something done quickly as a prototype.
 
In general, in the ViewModel. Only rarely would you do this is the View when are truly affecting GUI stuff and not indirectly updating the underlying model.

Take time to read some of Josh Smith's writings about MVVM to understand how MVVM applications are structured and laid out. His book "Advanced MVVM" is also an excellent read.


It takes a huge mindset change to go from the WinForms way of doing things to the WPF MVVM way of doing things. Some people just give up and end up using WPF the WinForms way. Please don't do this unless you are just writing a toy application to get something done quickly as a prototype.
thanks for the link , my goal is not to stay to winform way because this is an ide like app,and It has more than 4000 lines of code for form, when need to change something it's a mess.. Same thing when needed to add feature..
In general, in the ViewModel. Only rarely would you do this is the View when are truly affecting GUI stuff and not indirectly updating the underlying model.
All view have to show the same data but showed in different way. I have to take the event, change data according to the event and then refresh the chart.
 
As an aside, people have been successful managing large WinForms projects using the MVP pattern. Applying MVVM in WPF is essentially the same exercise. Basically it just comes down to being disciplined about separation of concerns. As tempting as it maybe to just stick that bit of logic into the event handler of the view, you have to resist the urge (and the mental justifications that it saves over 10-20 lines of code), and write the code that will send the message to the appropriate component, and that component have the logic.
 
Last question: what about open/save files? In winform I open it in button click event, and put the stream in a public array, in mvvm I should bind the button in the view with the command in the viewmodel, but the array should be in the model right?
 
That's correct.
 
Back
Top Bottom