Generate .xaml and .xaml.cs with Template T4
I am new in T4 Template and i want to generate .xaml files from T4 and taking some information form .xml file. So my question is: is it possible to generate .xaml files and all the M开发者_Python百科VVM infrastructure from T4 and is it possible to call and generate different files from T4 Template file ? Is it the best way to choose T4 Template for generation of wpf screens ? If not, how can we do for generating generic screens quickly ?
I see 5 questions:
- Is it possible to generate .xaml files and all the MVVM infrastructure from T4?
- Is it possible to call different files from T4 Template file?
- Is it possible to generate different files from T4 Template file?
- Is it the best way to choose T4 Template for generation of wpf screens?
- If not, how can we do for generating generic screens quickly?
Here are my answers:
- Yes, actually I believe T4 is very well suited to generate the boiler plate code that is usually required for MVVM.
- Yes, if you by this question mean that you wish to have a library of templates that you can reuse. The mechanism you use to get code-reuse in T4 is either normal assemblies that you reference or the <#@ include #> directive (very much like includes in PHP or ASP)
- Yes, but I would recommend you not to do this. Attempting this complicates the templates significantly and you should ask yourself what is the benefit of having different files for different generated classes. In certain cases you might be required to have seperate files (ie C# and XAML have to live in different files) but I would then recommend having two template files with diffent <#@ output #> directives.
- I don't understand this question, perhaps you can elaborate?
- It sounds like LightSwitch could be of interest to you. You could still use T4 to generate the model fragments needed for the screens.
In conclusion if you are looking for good resources on how to use T4 visit Oleg Sych's blog on T4. It's excellent.
精彩评论