Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a WPF Window to a Class Library Project [duplicate]

Tags:

c#

.net

window

wpf

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.

like image 515
CathalMF Avatar asked Dec 02 '22 11:12

CathalMF


1 Answers

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>
like image 193
CathalMF Avatar answered Dec 04 '22 14:12

CathalMF