I am planning to generate viewmodel classes from XAML files. We are developing a WPF app with MVVM pattern. The designers design the View(XAML) and they set the bindings. We are planning to use a T4 template use the Binding properties and generate the viewmodel class. While i do understand that the generated viewmodel will not be fully complete but atleast some percentage of the boilerplate code can generated is what my idea is. Is there any existing tool for this?How does the idea sound?
Share
So the scenario is; the designers write the view in XAML and you generate boilerplate code from that is later modified by developers to match the view requirements.
IMHO you won’t use T4 and code-generation to its full potential then. What I tend to do is generate C# code artifacts from some kind of view model description (could it be XAML, XML, C# or anything else). When the viewmodel changes I update the model description and fully regenerate the C# code artifacts. Developers never modify the generated code artifacts (as they might be regenerated and the changes lost), instead if they need to extend the view model with functionality they do it through partial classes and partial methods.
This will both reduce development cost and maintenance cost if properly done where as generating boilerplate code only reduce the development cost.
All IMHO of course.
The approach above can be implemented in Visual Studio 2008+ without any external tools or dependencies although some like to use plugins to add IntelliSense to T4 code.