7

I came across this problem today where I wanted to add a WPF Window to my existing class library project but it didn't exist in the Add New Item list.

I found a solution and just wanted to post it here as i couldn't find it elsewhere.

CathalMF
  • 9,705
  • 6
  • 70
  • 106
  • Before posting self answered questions make sure there is no duplicate. Now you are on a slim edge to prove you aren't plagiarist with that 7 years old [answer](https://stackoverflow.com/a/3574603/1997232). – Sinatr Nov 10 '17 at 14:23
  • @Sinatr I did do a search but it didnt show up. It can be marked as a duplicate. – CathalMF Nov 10 '17 at 14:27

1 Answers1

26

The solution is to open the .csproj in a text editor like notepad.

Add the following line under the first PropertyGroup xml tag.

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Save the changes and reload the project. The project will now be able to add WPF Windows as normal.

The complete PropertyGroup xml should look something like this:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{11EE2F8C-DFCF-451D-BA3E-84A4FB858848}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>TestApp</RootNamespace>
    <AssemblyName>TestApp</AssemblyName>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
  </PropertyGroup>
CathalMF
  • 9,705
  • 6
  • 70
  • 106
  • 2
    That is exactly correct. I just had to do that too. Also, if you're opening a Window from a Winform, you will need this line `ElementHost.EnableModelessKeyboardInterop(myWindow);` Before calling `myWIndow.ShowDialog()` so that the window will get keyboard input from user correctly. That method is located in the `System.Windows.Forms.Integration;` namespace. Not knowing about this could waste hours of your time! – Nik Nov 10 '17 at 14:27
  • 2
    Dont forget to Add References > Assemblies > Select System.Xaml > click OK – Nur Hidayah Roslee May 31 '21 at 08:51