Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add WPF Window in a Winforms Project in VS 2010

Is it possible to access all the WPF Items from a winforms Project when selecting "add new Item" in VS 2010 ? I only have access to WPF userControl by default.

I would like to add a WPF Window to a winforms project. Not just a user control.

EDIT : Short answer : This does not seem to be possible per se, but it is possible to add WPF resources and the necessary references manually.

like image 966
Mehdi LAMRANI Avatar asked Dec 16 '11 12:12

Mehdi LAMRANI


2 Answers

Apparently you cannot directly, but what you can do is add a new user control and then modify the code to make it a Window. Simply create a new WPF project, add a window and see what you need to change to turn your user control into a window.

like image 92
Tudor Avatar answered Oct 01 '22 18:10

Tudor


In my opinion the "cleanest" option is using this scheme:

  1. Create a WPF project (add any WPF windows you need). Lets call it "WPFProject"
  2. In the same solution create a WinForms project (add any Forms you need). Lets call it "MainProject".
  3. In MainProject add references to:

    • WPFProject
    • PresentationCore
    • PresentationFramework

Thats all, now you can open your WPF windows from your MainProject (eg. by pressing a button):

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim mywpfform = New WPFProject.MainWindow //MainWindow is the default name of your first WPF window. Obviously you can open any other
        mywpfform .Show()
End Sub
like image 39
Carlos Borau Avatar answered Oct 01 '22 20:10

Carlos Borau