mmmm
mmmm

Reputation: 2471

Hosting ActiveX control in WPF

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

Upvotes: 2

Views: 6040

Answers (1)

Quartermeister
Quartermeister

Reputation: 59129

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).

Upvotes: 5

Related Questions