C
C#2y ago
Gipper

❔ ViewModel normally how many classes?

In the context of MVVM are ViewModels only constituted by just one class, normally? I mean as in it being just one class that aggregates all the data from the Model that the Views may need to access...What would your general advice be in this respect?
5 Replies
canton7
canton72y ago
No? You'd have one ViewModel per "bit" of the UI (where "bit" is up to you to define, but normally represents one page/screen/pane/row/etc) ViewModels would normally map 1:1 to individual user controls, which you use to break up the UI
Gipper
GipperOP2y ago
They didnt teach us much about the "theory" in MVVM, what do you mean by individual user controls? Like each button?Each ComboBox, RadioButton, etc...?
canton7
canton72y ago
User controls which you write The terminology is slightly different depending on whether you're using WPF, web, etc But you'd normally split your UI up into different bits, right? At the least you'd have one View per page, but you might split pages up a bit as well, either to bring the complexity down a bit, or create reusable elements You normally wouldn't write a button as a View + a ViewModel: there's a point at which you switch to dumb controls. But I have written e.g. a button with a fancy progress bar on it as a view + a viewmodel, as there was logic in the viewmodel which I wanted to be able to unit-test
Gipper
GipperOP2y ago
Hmm...I'm probably gonna research ViewModels more thoroughly
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server