2

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?

vklu4itesvet
  • 375
  • 1
  • 4
  • 15

1 Answers1

4

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.

Community
  • 1
  • 1
Brian S
  • 5,675
  • 1
  • 22
  • 22
  • Maybe the asker wants to know why the ActiveX needs to be first touched by WinForm before it is usable in WPF? At least I'd like to know. Thanks for the examples – J Pollack May 22 '13 at 06:41