Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WPF网格或Viewbox中显示WinForms窗口_C#_Wpf_Winforms - Fatal编程技术网

C# 如何在WPF网格或Viewbox中显示WinForms窗口

C# 如何在WPF网格或Viewbox中显示WinForms窗口,c#,wpf,winforms,C#,Wpf,Winforms,在xml文件中: <Viewbox name="viewbox1"></Viewbox> 当我将window1分配给viewbox1时,它会显示一个错误,无法将窗口窗体转换为System.window.ElementUI 正确的方法是什么?您应该使用WPF的WinForms互操作主机控件WindowsFormsHost。 下面的代码是从 。你应该检查一下,以防你也有问题 由于您显然是新来者,我想给您一点提示: MSDN和MSDN上都有大量关于这个主题的资源,因此可以通过

在xml文件中:

<Viewbox name="viewbox1"></Viewbox>
当我将window1分配给viewbox1时,它会显示一个错误,无法将窗口窗体转换为System.window.ElementUI


正确的方法是什么?

您应该使用WPF的WinForms互操作主机控件WindowsFormsHost。 下面的代码是从

。你应该检查一下,以防你也有问题

由于您显然是新来者,我想给您一点提示: MSDN和MSDN上都有大量关于这个主题的资源,因此可以通过在您最喜欢的搜索引擎上进行简单搜索找到这些资源。 下一次,在发布问题之前,试着找到一个解决方案,以便只保留该主题的最佳答案,并将主持人结束问题的工作保存为重复。
有关这方面的更多信息,请查看

您需要使用WindowsFormsHost来完成此任务。您可以给我举个例子吗>您应该避免在WPF应用程序中使用WindowsForms-如果需要,请使用其他人提到的WindowsFormsHost。为什么不把WinForm重构成WPF呢?
windowformClass window1 = new windowformClass(); // this is the WinForms object, not WPF
viewbox1.Child = window1;
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
    new System.Windows.Forms.Integration.WindowsFormsHost();

// Create your control.
windowformClass window1 = new windowformClass();

// Assign the control as the host control's child.
host.Child = window1;

// Set the interop host control as the ViewBox child.
viewbox1.Child = host;