2010-06-18 72 views
1

我有一個ActiveX控件(用Delphi編寫),我想在WPF應用程序中託管它。當我嘗試將它加載到工具箱中並在設計時將其添加到XAML中時,它不會顯示在可用控件的列表中。有誰知道什麼過濾這個列表,爲什麼我看不到控制添加它?在WPF中託管ActiveX控件

編輯

這是我去 - 在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"; 
    } 

感謝

回答

5

退房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)

+0

我真正要問的是,當我採取http://msdn.microsoft.com/en-us/library/ms748870.aspx中的步驟時,我仍然沒有看到我的控制權。 – Mmarquee 2010-06-20 21:17:48

+0

根據你的回答和這篇文章http://blogs.msdn.com/b/jasonz/archive/2007/05/07/tip-trick-embedding-activex-in-wpf-with-windowsformshost-video-demo。 aspx我已經解決了我的問題。我必須將控件託管在一個winform用戶控件中,然後將其託管在WPF中 – Mmarquee 2010-06-21 23:59:19

相關問題