wpf - 在 WPF 中托管 ActiveX 控件

标签 wpf interop

我有一个 ActiveX 控件(用 Delphi 编写),我想将其托管在 WPF 应用程序中。当我尝试将其加载到工具箱以在设计时将其添加到 XAML 时,它没有显示在可用控件列表中。有谁知道什么过滤了这个列表以及为什么我看不到添加它的控件?

编辑

这就是我遇到的地方 - host.Child = (ax); 语句出现错误(无法将类型“DemoFrameControl.DemoFrameCtrl”隐式转换为“System.Windows.Forms.Control”) ),希望这有助于澄清我的问题

    private void WindowLoaded(object sender, RoutedEventArgs e)
    {
        // Create the interop host control.
        System.Windows.Forms.Integration.WindowsFormsHost host =
            new System.Windows.Forms.Integration.WindowsFormsHost();

        // Create the ActiveX control.
        DemoFrameControl.DemoFrameCtrl ax = new DemoFrameControl.DemoFrameCtrl();

        // Assign the ActiveX control as the host control's child.
        host.Child = (ax);

        // Add the interop host control to the Grid
        // control's collection of child controls.
        this.grid1.Children.Add(host);

        // Play a .wav file with the ActiveX control.
        //axWmp.URL = @"C:\WINDOWS\Media\Windows XP Startup.wav";
    }

谢谢

最佳答案

查看Walkthrough: Hosting an ActiveX Control in WPF

更新:

DemoFrameCtrl 是如何定义的?正如错误所述,它需要是 System.Windows.Forms.Control 的子类才能使用 WindowsFormsHost 。 ActiveX 控件包装器将从 AxHost 继承。它继承自Control。我认为如果您添加对 ActiveX 库的引用,Visual Studio 将生成包装器。如果没有,您可以尝试使用 Aximp.exe (Windows Forms ActiveX Control Importer)

关于wpf - 在 WPF 中托管 ActiveX 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3072957/

相关文章:

WPF全屏应用程序-多台监视器

COM 互操作引用计数指南

c# - 如何处理失败的 DllImport?

.net - 确定Word单元格是否合并

.net - 灾难恢复 - 逆向工程 XAML/BAML

c# - 如何将自定义 XAML 属性添加到继承 UserControl 的类?

.net - MVVM 从其他工作区(而不是主控制面板)打开新工作区

wpf - 为什么我的双向 WPF 绑定(bind)变得分离?

C_F_POINTER 导致未定义的数组

c - 将递归 C 结构移植到 Fortran