从 WinForms & 打开 WPF 窗口使用 WPF 应用程序链接表单应用程序 [英] Open a WPF Window from WinForms & link form app with WPF app

查看:28
本文介绍了从 WinForms & 打开 WPF 窗口使用 WPF 应用程序链接表单应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Visual Studio 2012 &我正在使用名为 Form1 & 的 Win Form 应用程序添加一个新项目,即 wpf Window,称为wpfWin".单击后,我想通过 Form1 中的按钮打开 wpfWin,它会打开 - 分离的窗口 -.

I'm using Visual studio 2012 & I'm using Win Form app called Form1 & add a new item which is wpf Window is called "wpfWin". I want to open the wpfWin through a button in the Form1 once it's clicked, it opened - separated windows-.

我试过 weblogs.asp 但我还没有找到WPF 自定义控件库"&一旦我跳过它,就会出现错误.有没有别的办法?!

I have tried weblogs.asp but I haven't found the "WPF Custom Control Library" & once I skip it an error appeared. Is there any other way?!

另外,如何在 WinForm & 中链接两个应用程序之一另一个WPF?!

Also, how can I link Two applications one in WinForm & the other Wpf ?!

推荐答案

打开 WPF 窗口在 WindowsForm APP 中,所以您对上述链接的教程和问题有疑问?WPF 自定义控件库"是您要在 Win-Forms 应用中使用的 WPF 窗口.

Open WPF window in WindowsForm APP so you are having issues with the above linked tutorial and question? The "WPF Custom Control Library" is the WPF window that you want to use in your Win-Forms app.

只是一个简短的解释,因为它通过问题和教程解释了几次.您将要打开当前正在处理的 win-forms 项目.然后您将需要转到解决方案资源管理器并右键单击解决方案,而不是项目,转到添加"并选择新建项目".

Just a brief explanation as it is explained a few times through the question and tutorial. You will want to open the win-forms project you are currently working on. Then you will want to go to Solution Explorer and right-click the SOLUTION, not the project, go to "Add" and select "New Project".

在添加新项目中,转到 Visual C#,然后转到左侧树中的 Windows.它们应该位于已安装的子菜单中.在主要部分中,您应该看到WPF 自定义控件库",单击它,然后将其命名为您想要的名称,然后单击确定.

In the add new Project go to Visual C# and then Windows in the tree on the left hand side. They should be located in the installed sub menu. In the main section you should see "WPF Custom Control Library" click on it and then name it what you would like and click ok.

在项目中添加一个Window(WPF)控件,这个窗口就是你要打开的WPF窗口.

Add a Window(WPF) control to the project, this window would be the WPF window that you want to open.

然后从 WinForm 中,像这样打开它:

Then from the WinForm, open it like so:

var wpfwindow = new WPFWindow.Window1();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();

但是请确保您有以下 using 语句:

However ensure you have the following using statements:

using System; //Given 
using System.Windows.Forms; //Given
using System.Windows.Forms.Integration; //Not so Given.

您还需要添加一些引用以使其正常工作,以下是您需要添加到 win-forms 的列表:

You will need to add some references as well to make this work correctly, here is the list which should be all you need to add to a win-forms:

 PresentationCore
 PresentationFramework
 WindowsFormsIntegration
 WindowsBase
 System.Xaml
 YourWpfControlProjectName

您应该使用 VS 中的引用选择器将这些添加到您的 Win-forms 项目中,方法是右键单击解决方案资源管理器中的引用文件夹并添加一个新引用.所有引用都位于框架"选项卡中,没有解决方案选项卡中的 WPF 控件.

You should add these to your Win-forms project using the reference picker in VS by right-clicking the reference folder in the solution explorer and adding a new reference. All of the references are located in the Framework tab, sans your WPF control which is in the solution tab.

这篇关于从 WinForms & 打开 WPF 窗口使用 WPF 应用程序链接表单应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆