我发现的一个部分解决方案是从您的 WPF 构造函数中调用它: System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop(); (您需要引用 dll WindowsFormsIntegration.dll)
我说部分是因为并非所有按键都按预期工作。例如,对于简单的表单似乎可以正常工作。
请参阅:http :
//msdn.microsoft.com/en-us/library/system.windows.forms.integration.windowsformshost.enablewindowsformsinterop(v=vs.100).aspx
我最终设法通过将 winform 托管在 WPF 表单内的 WindowsFormsHost 控件内来解决该问题。
public partial class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
Form winform = new Form();
// to embed a winform using windowsFormsHost, you need to explicitly
// tell the form it is not the top level control or you will get
// a runtime error.
winform.TopLevel = false;
// hide border because it will already have the WPF window border
winform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.windowsFormsHost.Child = winform;
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果您有关闭表单的按钮,您可能还需要连接 winform 关闭事件。
| 归档时间: |
|
| 查看次数: |
2915 次 |
| 最近记录: |