简体   繁体   English

将WPF控件公开为ActiveX控件

[英]Exposing WPF control as ActiveX control

Why it is impossible to expose WPF control as ActiveX directly , without hosting wpf control within WinForms control and then exposing WinForms control as ActiveX? 为什么在没有将WPF控件托管在WinForms控件中然后将WinForms控件公开为ActiveX的情况下直接将WPF控件公开为ActiveX是不可能的? All articles I've read : - WPF User Control in a Dialog System Application - WPF Vista Gadgets using ActiveX post it as a fact? 我读过的所有文章:- 对话框系统应用程序中的WPF用户控件 - 使用ActiveX的WPF Vista小工具将其发布为事实吗? but no one explains why? 但是没有人解释为什么?

One big reason is that they are entirely different graphics and rendering systems. 一个很大的原因是它们是完全不同的图形和渲染系统。 When you create a WPF Window, it is completely different from a Win32 Window, and therefore interacts with the host OS differently. 创建WPF窗口时,它与Win32窗口完全不同,因此与主机OS的交互方式也不同。 Think of .NET vs. COM. 想一想.NET与COM。 These are entirely different "frameworks" that both run on Windows, and can inter-operate, however they are completely different, and require some hoops in order to work together. 这些都是完全不同的“框架”,都可以在Windows上运行,并且可以互操作,但是它们是完全不同的,并且需要一些箍才能一起工作。 I think WPF is to WinForms as .NET is to COM. 我认为WPF适用于WinForms,而.NET适用于COM。

Any details I provide are probably over-simplifying it, but I'll try with a couple examples: 我提供的任何细节都可能简化了它,但是我将尝试几个示例:

For example, in Win32, each control on a window (every label, button, etc.) is its own "window" with its own WindowHandle (and message pump) that receives messages from Windows. 例如,在Win32中,窗口上的每个控件(每个标签,按钮等)都是其自身的“窗口”,具有自己的WindowHandle(和消息泵),该窗口从Windows接收消息。 In WPF, there is only 1 Window (the top level window, and even this is probably not entirely true, since a WPF window is not a window in the sense of Win32) and WPF is responsible for delivering any messages from the OS to the appropriate element on the screen. 在WPF中,只有1个窗口(顶层窗口,甚至可能也不是完全正确的,因为WPF窗口不是Win32的窗口),WPF负责将所有消息从OS传递到屏幕上的适当元素。 You can read more about this (with some links to sources) here . 您可以在此处阅读有关此内容的更多信息(带有一些到资源的链接)。

Another example is that WPF uses a different approach to rendering visual elements on the screen. 另一个示例是WPF使用不同的方法在屏幕上呈现视觉元素。 WPF uses a Retained Mode Graphics system, which is different from the Immediate Mode Graphics systems that Win32 and other GDI/GDI+ frameworks. WPF使用保留模式图形系统,该系统不同于Win32和其他GDI / GDI +框架的立即模式图形系统。 You can read more about that here . 您可以在此处阅读更多有关此内容的信息

There are many other reasons, I'm sure, but at the end of the day, they are just completely different technologies. 我敢肯定,还有许多其他原因,但归根结底,它们只是完全不同的技术。 So in order to get them to work together, you need to jump through some hoops (using the two Host controls for interop). 因此,为了使它们一起工作,您需要跳过一些箍(使用两个用于互操作的Host控件)。 I would suggest the more you read about WPF, specifically advanced topics about the graphics and rendering, the better you'll understand why it is not just "compatible" with WinForms. 我建议您阅读有关WPF的内容越多,尤其是有关图形和渲染的高级主题,则您将更好地理解为什么它不仅仅与WinForms“兼容”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM