from the design point of view, I have a complex GUI, what is the recommended granularity for cutting the GUI (Window) into ViewModels, UserControls and DataTemplates. Let’s assume I have a window showing list of entities in DataGrid, then some filters in ComboBoxes, some detail…
How many ViewModels should I create? …and DataTemplates and UserControls.
Thank you very much for a good WPF/MVVM design pattern idea.
Although your question is not very clear, I’ll try to answer it. The number of
ViewModelsis… just up to you.My personal approach is to separate my UI into many different custom
UserControls, with oneViewModelper control. It allows me to have a crystal-clear architecture with a lot of smart controls designed for one task each. As an example, for my manager application, I have:– One
UserControldesigned to list all the users– Another one designed to create or edit a user
– and one more designed to monitor user’s activity.
Separating your application into different task-driven
UserControlswill help you having:Bindingsflying everywhere.About
DataTemplates, again, I usually separate the general templates into differentResourceDictionaries.Anyway, there is no “right way” neither “wrong way” to do, I think there is just “your way”. For me, the more granular my code is, the more understandable it will be, assuming that the components are not small enough to be useless. One separated component should be designed for one main goal. Once you’ve done this separation, MVVM will help you a lot!