Hosting ActiveX control in WPF

随声附和 提交于 2019-12-24 03:55:16

问题


I have an ActiveX control (written in Delphi) which I want to host in a WPF application. When I try to load it into the toolbox to add it to the XAML at design time, it is not shown in the list of available controls. Does anyone know what filters this list and why I can't see the control to add it?

Edit

This is where I get to - the host.Child = (ax); statement gets an error (Cannot implicitly convert type 'DemoFrameControl.DemoFrameCtrl' to 'System.Windows.Forms.Control'), hope this helps clarify my problem

    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";
    }

Thanks


回答1:


Check out Walkthrough: Hosting an ActiveX Control in WPF.

Update:

How is DemoFrameCtrl defined? Like the error says, it needs to be a subclass of System.Windows.Forms.Control to use WindowsFormsHost. An ActiveX control wrapper will inherit from AxHost which inherits from Control. I think Visual Studio will generate the wrapper if you add a reference to the ActiveX library. If not, you can try using Aximp.exe (Windows Forms ActiveX Control Importer).



来源:https://stackoverflow.com/questions/3072957/hosting-activex-control-in-wpf

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