我有一个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";
}
Run Code Online (Sandbox Code Playgroud)
谢谢
更新:
怎么DemoFrameCtrl定义?就像错误说的那样,它需要是一个System.Windows.Forms.Control要使用的子类WindowsFormsHost.ActiveX控件包装器将继承自的AxHost继承Control.我认为如果添加对ActiveX库的引用,Visual Studio将生成包装器.如果没有,您可以尝试使用Aximp.exe(Windows窗体ActiveX控件导入程序).