我正在走过WPF Walkthrough: Hosting a Windows Forms Composite Control in WPF.
基本上它首先使用Windows Form创建了一个用户控件,然后将其添加到WPF应用程序中。
我已完成用户控件,现在我正在实现代码隐藏文件。由于它只是来自MSDN链接的复制和粘贴代码,所以让我们看一下该方法。
private void Init(object sender, EventArgs e)
{
app = System.Windows.Application.Current;
myWindow = (Window)app.MainWindow;
myWindow.SizeToContent = SizeToContent.WidthAndHeight;
wfh.TabIndex = 10;
initFontSize = wfh.FontSize;
initFontWeight = wfh.FontWeight;
initFontFamily = wfh.FontFamily;
initFontStyle = wfh.FontStyle;
initBackBrush = (SolidColorBrush)wfh.Background;
initForeBrush = (SolidColorBrush)wfh.Foreground;
(wfh.Child as MyControl1).OnButtonClick += new MyControl1.MyControlEventHandler(Pane1_OnButtonClick);
UIIsReady = true;
}
有错误
无法将类型'System.Windows.Forms.Control'隐式转换为'object'
代码:
(wfh.Child as MyControl1).OnButtonClick += new MyControl1.MyControlEventHandler(Pane1_OnButtonClick);
如何纠正?