创建自定义设计时环境
我的问题与 WPF 的设计时支持有关。从 MSDN 我读到,
WPF设计器提供了一个框架 以及一个公共 API,您可以使用它 实施自定义装饰器、工具、 属性编辑和设计师。
但我发现的绝大多数示例都很琐碎,并没有说明如何在现有 WPF 应用程序中创建自定义设计器。在过去的一年里,我们已将应用程序从 Windows 窗体迁移到 WPF,下一步将采用现有的 WinForms 面板设计器,并在 WPF 中重写它。
可以说,这将是一个巨大的工程。但我什至不知道从哪里开始。我想知道你们中是否有人有过类似的为 WPF 应用程序编写自定义设计器的经历,以及它是什么样的。更好的是,如果您可以比较和对比 WinForms 设计器和 WPF 设计器之间的功能,或者解释从前者到后者的过渡,那将会很有帮助。如果您知道任何演示自定义设计环境(带有自定义控件等)的简单示例,那将非常有益。
总而言之,我只是想知道是否有很多人已经这样做了,以及他们的结果如何。
编辑:澄清一下,是的,我说的是托管 WPF 设计器。看来这甚至不可能,这是一个巨大的挫折。这是我们当前的 WinForms 设计器的屏幕截图。正如您所看到的,它用于创建自定义的用户界面。您可以将自定义控件拖到其上并进行设计,然后将面板置于“运行模式”,在该模式下所有控件都将发挥作用。
不用花几个月的时间来编写我们的设计器,这在 WPF 中可能吗? .NET 4.0 和 VS2010 怎么样?这些会添加任何设计器功能吗?
替代文本 http://img94.imageshack.us/img94/5378/oldpaneldesigner.png< /a>
My question is related to the design-time support of WPF. From MSDN I read,
The WPF Designer provides a framework
and a public API which you can use to
implement custom adorners, tools,
property editors, and designers.
But the vast majority of the examples I have found are trivial, and do not illustrate much concerning the creation of a customized designer in an existing WPF application. We have migrated our application from Windows Forms to WPF over the past year, and the next step will be to take an existing WinForms Panel designer, and rewrite it in WPF.
Suffice it to say that this will be a huge project. But I don't even know where to begin. I am wondering if any of you have had similar experiences writing a customized designer for a WPF application, and what it was like. Even better, if you could compare and contrast the functionality between the WinForms designer and the WPF designer, or explain the transition from the former to the latter, that would be helpful. If you know of any simple examples that demonstrate a customized design environment (with custom controls, etc.) that would be extremely beneficial.
All in all, I am just wondering if many people have undertaken this yet, and what their results have been.
EDIT: To clarify, yes, I am talking about hosting a WPF designer. It appears that this may not even be possible, which is a huge setback. Here is a screenshot of our current WinForms designer. As you can see, it is used to create customized user interfaces. You can drag custom controls onto it and design them, then put the panel into a "run mode" in which all of the controls become functional.
Short of spending months writing our designer, would this be possible in WPF? What about .NET 4.0 and VS2010? Will those add any designer functionality?
alt text http://img94.imageshack.us/img94/5378/oldpaneldesigner.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

不幸的是,根据您具体想要做什么,可能没有一个好的答案。您的问题对于您到底想做什么有点模糊。您是否尝试简单地扩展 Visual Studio 中的现有设计器,或者尝试将 WPF 设计器托管在您自己的单独应用程序中?
如果是后者,不幸的是您可能无法做到这一点。 WinForms 设计器实际上是 .NET Framework(不是 Visual Studio)的一部分,因此任何提供正确托管环境的应用程序都可以访问它。 MSDN 上有一篇关于如何执行此操作的好文章,以及来自 DivElements 的另一篇文章。
许多人在其他论坛中询问是否可以使用 Cider(WPF 设计器的代号)和 看来答案是否定的。您唯一可能的替代方案是重新设计您的应用程序以使用 Visual Studio 独立 Shell 。 此处提供了有关选项的详细概述。
编辑: 看来 SharpDevelop 可能有一个可供您使用的 WPF 设计器。我不能 100% 确定他们是否开发了自己的,或者他们是否找到了托管它的方法,但您可以查看他们的来源并自行决定。转到 Sharp Develop 的每日构建(官方文档中没有尚未构建)并获取最新的每日构建。在该 zip 文件中,查看 Samples/XamlDesigner 目录。
Unfortunately, there may not be a good answer depending on exactly what you want to do. Your question is a little vague as to exactly what you are trying to do. Are you trying to simply extend the existing designer within Visual Studio, or are you trying to host the WPF designer in your own separate application?
If the latter, you may unfortunately not be able to do that. The WinForms designer was actually part of the .NET Framework (not Visual Studio) and so was accessible to any application that provided the correct hosting environment. There is a good article on MSDN on how to do that here, and another one on from DivElements here.
Many people have asked in other forums whether the same is possible using Cider (the code name for the WPF designer), and it seems like the answer is no. Your only potential alternative is to redesign your application to make use of the Visual Studio Isolated Shell. There is a good overview of the options here.
EDIT: It looks like SharpDevelop may have a WPF designer you can use. I'm not 100% sure if they developed their own, or if they figured out a way to host it, but you can look at their source and decide for yourself. Go to the Daily Builds of Sharp Develop (it's not in the official build yet) and get the latest daily build. In that zip file, look at the Samples/XamlDesigner directory.