wpf - other View(s) dependency? -
i have view image , viewmodel have commands handle button (1,2,3,4) clicks. in work area allow user give inputs. depending upon input users allowed click button;
each button leads 1 new window(view viewmodel; model taken inputs). new window have own logic showing data depending upon model injected viewmodel.
as per mvvm standards, specify respective view , viewmodels each button? (in view / view model). how can specify same?
basically viewmodel link between view , model, each combination of view , model should have separate viewmodel (if valid).
in experience in cases dealing 2 kinds of views:
- small views such icons, advanced buttons , on (which more isolated , more have no reference parents easy manage , generalized)
- large views such windows, panels (which have lot of children , more changed later)
for small views common viewmodels can used multiple views. large views (considering possible changes in future) it's better not use single shared viewmodel. it's helpful use base viewmodel class implement shared functionality (if any).
so keeping in mind , focusing stay standard, suggest:
viewmodels secondary windows
: (according question think need 4) each have independent functionality (you can derive them basewindowvm).best practice here not let them know parent (mainwindowvm
) , set event handlers when instantiated. way can avoid code coupling.mainwindowvm
: consists of 4 commands , other inputs. each command these steps:- instantiates view
- instantiates
viewmodel secondary window
based on input - set vm's event handlers
- assign vm datacontext of view
- add vm list in
mainwindowvm
(if want keep track of these windows) - showdialog()
the important part since viewmodels communicate each other, linking views each other make more complicated , more difficult manage. views islands bindings viewmodels , else viewmodels.
Comments
Post a Comment