Possible Duplicate:
How to define the usercontrols in mvvm pattern?
I’m trying to write my first WPF application using MVVM. I created a user control consisting of 2 parts, a DataGrid and a detail view (shows the details of the selected row in the DataGrid). This control is suppose to load and show different data models (like customers, products and etc.) but Since it appears to be no way to use generic user controls, I find my user control useless. and frankly I start to think any user control in MVVM pattern would be useless. Is there any alternatives for preventing unnecessary Copy/Paste of the same DataGrid and detail view, in my views?
thx in advance
First of all, it is possible to use generic user controls. But besides that, it’s probably not what you want.
What you need to do is create a user control that can be re-used. There are several options:
To create view models for a specific user control including lazy loading of view models, you can use Catel. For more info, see this documentation.
Disclaimer: I am one of the developers of Catel, but if other people know other ways, I am happy to hear them.