将WPF控件公开为ActiveX控件 [英] Exposing WPF control as ActiveX control

查看:110
本文介绍了将WPF控件公开为ActiveX控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在没有将WPF控件托管在WinForms控件中然后将WinForms控件公开为ActiveX的情况下,直接将WPF控件公开为ActiveX是为什么?我已阅读的所有文章:
-对话框系统应用程序中的WPF用户控件
-使用ActiveX的WPF Vista小工具
将其发布为事实吗?

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?

推荐答案

一个重要原因是它们是完全不同的图形和渲染系统。创建WPF窗口时,它与Win32窗口完全不同,因此与主机OS的交互方式也不同。想一想.NET与COM。这些都是完全不同的框架,都可以在Windows上运行,并且可以互操作,但是它们是完全不同的,并且需要一些箍才能一起工作。我认为WPF就像WinForms一样,.NET就是COM。

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:

例如,在Win32中,窗口上的每个控件(每个标签,按钮等)都是其自己的窗口,具有自己的WindowHandle(和消息泵),从Windows接收消息。在WPF中,只有1个窗口(顶层窗口,甚至可能也不是完全正确的,因为WPF窗口不是Win32的窗口),WPF负责将所有消息从OS传递到屏幕上的适当元素。您可以在此处中阅读有关此内容的更多信息。

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.

另一个示例是WPF使用另一种方法在屏幕上呈现可视元素。 WPF使用保留模式图形系统,该系统不同于Win32和其他GDI / GDI +框架的立即模式图形系统。您可以在此处了解更多信息。

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.

我敢肯定还有很多其他原因,但归根结底,它们只是完全不同的技术。因此,为了使它们一起工作,您需要跳过一些箍(使用两个用于互操作的Host控件)。我建议您阅读有关WPF的内容越多,尤其是有关图形和渲染的高级主题,则您将更好地理解为什么它不仅仅与WinForms兼容。

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.

这篇关于将WPF控件公开为ActiveX控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆