在 WPF 中使用 ActiveX 控件
我正在尝试在 WPF 应用程序中托管 ActiveX 控件。在尝试使用网络上和此处的现有信息后,我陷入了死胡同。
我需要使用提供的 ActiveX 控件与 紫外线功率计。他们提供应用程序注册并使用该控件,甚至包括一些有用的演示应用程序。如果需要的话,我删除了 OCX 文件并将其放在此处。您将无法与功率计交谈,但应用程序和演示仍将成功加载 ActiveX 控件。
我创建了一个简单的 Windows 窗体应用程序。我能够将 ActiveX 控件引入工具栏,将其放入我的窗体中,一切都很好。他们提供的演示应用程序也可以做到这一点。
然而,让它在 WPF 环境中工作是另一回事。该控件无法添加到工具箱并“拖”到应用程序中。
到目前为止,我已经尝试了两种技术:
- 技术找到 here 。我可以添加对控件的引用,但随后我进入了命名空间地狱。它建议的 xmlns:ax 命名空间找不到该信息。这是我根据对象查看器告诉我的内容进行的尝试:
xmlns:ax="clr-namespace:OphirUsbXLib; assembly=Interop.OphirUsbXLib"
- 找到的技术 此处。这本质上是创建一个新项目,该项目创建一个基于 Windows 窗体的库,其中包含 ActiveX 控件(哎呀)。我可以添加 Windows 窗体主机,但无法访问其中的 ActiveX 控件。我可以公开控件,但我仍然无法调用方法等。这看起来不是正确的解决方案。
简而言之,我有一个 ActiveX 控件,它在 Forms 中工作得很好,但在 WPF 中工作却很糟糕。
任何见解表示赞赏!
I'm attempting to host an ActiveX control in a WPF app. After attempting to use existing info on the web and here, I've hit a dead-end.
I need to use an ActiveX control provided to communicate with a UV power meter. They provide an application that registers and uses the control and even includes some useful demo apps. I stripped out the OCX file and put it here if needed. You won't have the power meter to talk to, but the app and demos will still load the ActiveX control successfully.
I created a simple Windows Forms application. I was able to bring the ActiveX control into the toolbar, drop it into my form, and everything is fine. The demo apps they provide do this as well.
However, getting this to work in a WPF environment is another story. The control can't be added to the toolbox and "dragged" into the app.
So far I've tried two techniques:
- Technique found here. I am able to add a reference to the control, but then I enter namespace hell. The xmlns:ax namespace it suggests making cannot find the information. Here's my attempt based on what the object viewer tells me:
xmlns:ax="clr-namespace:OphirUsbXLib;assembly=Interop.OphirUsbXLib"
- Technique found here. This is essentially to create a new project that creates a library based on Windows Forms, which contains the ActiveX control (yikes). I am able to add the Windows Forms Host, but I cannot get access to the ActiveX control within. I can make the control public, but I still cannot call methods etc. This doesn't look like the right solution.
In short, I have an ActiveX control that works beautifully in Forms, but is a real bitch to get working in WPF.
Any insight is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,我会考虑制作一个 WinForms 用户控件来包装您尝试使用的 ActiveX 控件。
您可以创建公共属性和方法,以公开 ActiveX 控件上的每个所需属性和方法,然后将此 WinForms UC 托管在 WPF WinFormsHost 控件中。
我已经做了类似的事情,相反,在 WinForms UserControl 中托管 WPF UserControl,然后在旧应用程序中的 VB6 Form 上托管它。
In this situation I would consider making a WinForms usercontrol which wraps the ActiveX control you are trying to use.
You could make public properties and methods which expose each of the required properties and methods on the ActiveX control, and then host this WinForms UC on the in a WPF WinFormsHost control.
I have already done something similar to this, in reverse, hosting a WPF UserControl in a WinForms UserControl, then hosting that on a VB6 Form in a legacy application.