WPF DataTemplate/ControlTemplate 和 VS2008 设计器
假设您的 WPF 窗口由许多使用 DataTemplates / ControlTemplates 的元素(ItemControls ...)组成 但您想了解每个 DataTemplate 在 VS Designer 中的外观。 更重要的是,如果您将 ControlTemplate 定义为位于另一个文件中的模板,以便能够查看它的内容。
类似于 ASP.NET 中的 MasterPage 和 ChildElements 您始终可以看到您将哪些元素组合在一起。
这在 WPF 中也可能吗? 否则..我对 DataTemplate 所做的每一个更改都可以在耗时的编译和启动后看到。
谢谢各位..
Suppose you have WPF Window composed of many elements that are using DataTemplates / ControlTemplates (ItemControls ... )
But you want to see how every DataTemplate looks like in VS Designer.
What more, if you define a ControlTemplate from as a Template located in another file to be able to view it with the content.
Something like MasterPage and ChildElements in ASP.NET
You can always see what elements have you put together.
Is this possible in WPF too?
Otherwise.. every change I make to the DataTemplate can be seen after a long-time-consuming compilation and start.
Thank you guys..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Stefan,
我认为您可以通过创建设计时类来做到这一点,如下面的链接所述:
http://karlshifflett.wordpress.com/2008/10/11/viewing-design- time-data-in-visual-studio-2008-cider-designer-in-wpf-and-silverlight-projects/
希望这会有所帮助。
Stefan,
I think that you can do this by creating Design Time class as described in the link below:
http://karlshifflett.wordpress.com/2008/10/11/viewing-design-time-data-in-visual-studio-2008-cider-designer-in-wpf-and-silverlight-projects/
Hope this helps.
要非常简单地完成此操作,只需在构造函数中设置 DataContext:
请注意代码已被注释掉。当您想查看数据时,只需取消注释代码即可。
#if !RELEASE
可以防止您意外地将示例数据包含在您的版本中(并且避免花费任何 CPU 来加载它)。如果您的示例数据很大,只需将其放入 XML 或数据库中并加载即可:
无论哪种情况,每当您取消注释代码时,示例数据都会显示在设计器中。执行应用程序时,它将被替换为真实数据。
To do this extremely simply, just set a DataContext in your constructor:
Notice the fact that the code is commented out. When you want to see data, just uncomment the code. The
#if !RELEASE
protects you from accidentally including the sample data in your release (and from spending any CPU loading it).If your sample data is big, just put it in XML or in a database and load it:
In either case, the sample data will show up in the designer whenever you uncomment the code. When executing your application it will be replaced with the real data.