I'm trying to work out the best way to couple my Views and ViewModels in MVVM and I've settled on the ViewModel-first approach using typed DataTemplates, as described in this article and in this answer. I'm using Prism and have multiple modules which have their own projects/class libraries.
My question is: Where should my DataTemplates live in my solution?
- Should I put the DataTemplates in a Resource Dictionary which lives in the same project that has the types/ViewModels it renders?
- Should I put the DataTemplates in a Resource Dictionary which lives in the project which has the application's MainWindow (i.e. Shell.xaml)?
- Should these Resource Dictionaries then be added to
App.Current.MainWindow.Resources.MergedDictionaries
?
I hope this is enough information to describe what I'm trying to do.
Update: see comments of selected answer.
Resource Dictionaries
. The problem is that this Infrastructure project is referenced by all my other projects/modules. In order to use typedDataTemplates
I'll require references to the projects that contain my ViewModels which would mean creating a circular dependency. Should I create a separate project to hold onlyDataTemplates
? – Blackface