Assume I have several Views in my WPF application that all show a report, but each View shows a different report.
I created a base ViewModel that contains all the stuff all reports have in common. Each report View gets its own ViewModel that is derived from the base ViewModel. These derived ViewModels have the following responsibilities:
- Generate the Report Data
- Format the Report Data for printing
- Provide properties for the report parameters
- Provide Commands for additional actions that can be executed on the generated report (optional)
That’s all fine and concise, however, the Views are a complete mess.
Basically, each View is the same with only some minor changes, for example:
- Provide different controls for the report parameters
- Provide buttons that bind to the Commands for the additional actions
I would like to achieve the following:
- Have a base View that defines all the stuff all report Views have in common, similar to a Site.master in ASP.NET. This would contain the search button, the print button, the grid the report is shown in etc…
- Have concrete Views – one for each report – that defines only the controls for the search parameters and the buttons for the additional actions
How to do this? Googling for WPF master page brings up a lot of custom made solutions – surely there must be a standard way?
In WPF, a placeholder
ContentControl.ContentTemplatecan be set automatically based on itsDataTemplate.DataTypeif theContentis set to that sameDataTypeinstance.http://www.japf.fr/2009/03/thinking-with-mvvm-data-templates-contentcontrol/