在Windows窗体应用程序中托管WPF应用程序

时间:2022-05-20 00:15:21

I am using the following code to host a WPF application inside my Windows Forms application:

我使用以下代码在我的Windows窗体应用程序中托管WPF应用程序:

var clientApplication = Process.Start("C:\\WpfApplication1.exe");

SetParent(clientApplication.MainWindowHandle, this.Handle);

The WPF app is opening as an independent app, how to force it to open withing the main windows form

WPF应用程序作为一个独立的应用程序打开,如何强制它打开主窗口窗体

1 个解决方案

#1


3  

A "complete application", if it is a desktop application includes at least 1 Window object, which cannot be hosted inside anything because it is a Window. What you will need to do is to remove any top level Windows from your WPF application and then you can host indivual Views (UserControls or other type of non-window elements) using an ElementHost.

一个“完整的应用程序”,如果它是一个桌面应用程序,则包含至少一个Window对象,由于它是一个Window,因此无法在任何内容中托管。您需要做的是从WPF应用程序中删除任何*Windows,然后您可以使用ElementHost托管单个视图(UserControls或其他类型的非窗口元素)。

Edit: Be aware that in order to do this, you have to either reference the WPF application project from your winforms project, or load everything in runtime via reflection. There's no way you can make a .Exe file be hosted inside another window.

编辑:请注意,为了执行此操作,您必须从winforms项目引用WPF应用程序项目,或者通过反射在运行时加载所有内容。您无法将.Exe文件托管在另一个窗口中。

#1


3  

A "complete application", if it is a desktop application includes at least 1 Window object, which cannot be hosted inside anything because it is a Window. What you will need to do is to remove any top level Windows from your WPF application and then you can host indivual Views (UserControls or other type of non-window elements) using an ElementHost.

一个“完整的应用程序”,如果它是一个桌面应用程序,则包含至少一个Window对象,由于它是一个Window,因此无法在任何内容中托管。您需要做的是从WPF应用程序中删除任何*Windows,然后您可以使用ElementHost托管单个视图(UserControls或其他类型的非窗口元素)。

Edit: Be aware that in order to do this, you have to either reference the WPF application project from your winforms project, or load everything in runtime via reflection. There's no way you can make a .Exe file be hosted inside another window.

编辑:请注意,为了执行此操作,您必须从winforms项目引用WPF应用程序项目,或者通过反射在运行时加载所有内容。您无法将.Exe文件托管在另一个窗口中。