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.
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".
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.
Add a Window(WPF) control to the project, this window would be the WPF window that you want to open.
Then from the WinForm, open it like so:
var wpfwindow = new WPFWindow.Window1();
ElementHost.EnableModelessKeyboardInterop(wpfwindow);
wpfwindow.Show();
However ensure you have the following using statements:
using System; //Given
using System.Windows.Forms; //Given
using System.Windows.Forms.Integration; //Not so Given.
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
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…