Exposing WPF control as ActiveX control

倖福魔咒の 提交于 2019-12-13 03:17:20

问题


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? All articles I've read : - WPF User Control in a Dialog System Application - WPF Vista Gadgets using ActiveX post it as a fact? but no one explains why?


回答1:


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. Think of .NET vs. 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. I think WPF is to WinForms as .NET is to 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. 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. 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 uses a Retained Mode Graphics system, which is different from the Immediate Mode Graphics systems that Win32 and other GDI/GDI+ frameworks. 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). 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.



来源:https://stackoverflow.com/questions/11294297/exposing-wpf-control-as-activex-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!