使用模板 T4 生成 .xaml 和 .xaml.cs

发布于 2024-11-30 08:10:37 字数 166 浏览 1 评论 0原文

我是 T4 模板的新手,我想从 T4 生成 .xaml 文件并从 .xml 文件中获取一些信息。所以我的问题是:是否可以从 T4 生成 .xaml 文件和所有 MVVM 基础设施,是否可以从 T4 模板文件调用并生成不同的文件? 这是选择 T4 模板生成 wpf 屏幕的最佳方式吗?如果没有,我们如何快速生成通用屏幕?

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 MVVM 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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜访吸血鬼 2024-12-07 08:10:37

我看到 5 个问题:

  1. 是否可以从 T4 生成 .xaml 文件和所有 MVVM 基础设施?
  2. 是否可以从 T4 模板文件调用不同的文件?
  3. 是否可以从 T4 模板文件生成不同的文件?
  4. 这是选择 T4 Template 来生成 wpf 屏幕的最佳方式吗?
  5. 如果没有,我们如何快速生成通用屏幕?

以下是我的回答:

  1. 是的,实际上我相信 T4 非常适合生成 MVVM 通常所需的样板代码。
  2. 是的,如果您提出这个问题意味着您希望拥有一个可以重复使用的模板库。在 T4 中用于实现代码重用的机制是您引用的普通程序集或 <#@ include #> 。指令(非常类似于 PHP 或 ASP 中的 include)
  3. 是的,但我建议您不要这样做。尝试这样做会使模板变得非常复杂,您应该问自己为不同的生成类使用不同的文件有什么好处。在某些情况下,您可能需要拥有单独的文件(即 C# 和 XAML 必须位于不同的文件中),但我建议使用两个具有不同 <#@ 输出 #> 的模板文件。指令。
  4. 这个问题我不太明白,能否详细解释一下?
  5. 听起来您可能会对 LightSwitch 感兴趣。您仍然可以使用 T4 生成屏幕所需的模型片段。

总之,如果您正在寻找有关如何使用 T4 的优质资源,请访问 Oleg Sych 在 T4 上的博客太棒了

I see 5 questions:

  1. Is it possible to generate .xaml files and all the MVVM infrastructure from T4?
  2. Is it possible to call different files from T4 Template file?
  3. Is it possible to generate different files from T4 Template file?
  4. Is it the best way to choose T4 Template for generation of wpf screens?
  5. If not, how can we do for generating generic screens quickly?

Here are my answers:

  1. Yes, actually I believe T4 is very well suited to generate the boiler plate code that is usually required for MVVM.
  2. 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)
  3. 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.
  4. I don't understand this question, perhaps you can elaborate?
  5. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文