Cuero
Cuero

Reputation: 1209

Can't find ResourceDictionary in Add New Item Window

When I create a new WPF project I can find ResourceDictionary in Add New Item Window. But I've another Project I can't find that and I don't know why. Only UserControl but no ResourceDictionary

UPDATE: The project was for .net 3.5 originally, but now it also has a version for .net 4.0. It means there're two .sln files (one for 3.5 and the other for 4.0) both for the same project.

Upvotes: 19

Views: 11189

Answers (3)

KulaGGin
KulaGGin

Reputation: 1242

Close the project. Create a new project that is of the type of WPF project you would have used(or use existing one). Then open the .csproj file of WPF project in text editor. Find the ProjectTypeGuids element.

Open your existing .csproj file in notepad. See if it has ProjectTypeGuids element. If it does, append GUID(without the ProjectTypeGuids) from WPF project in your existing project. If your existing .csproj file doesn't have ProjectTypeGuids element in it, copy ProjectTypeGuids from your WPF project together with GUID and paste it in your existing project in the first PropertyGroup element.

Reload your project in Visual Studio. You should be able to add all the WPF file types now.

I believe the GUIDS are the same for everyone so the values you need should be: {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ... this should save you the step of creating a new project.

So if you have a class library project, just add

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

To the first PropertyGroup element in your .csproj file.

Upvotes: 0

MatrixManAtYrService
MatrixManAtYrService

Reputation: 9131

Add the following line to Project.csproj

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

It should be a child of the <PropertyGroup> tag, like so:

    <Project>
      <PropertyGroup>
        ....
        <ProjectTypeGuids>{guids};{go};{here}</ProjectTypeGuids>
        ...
      </PropertyGroup>
    ...
    </Project>

This post does a good job of explaining why this works.

Upvotes: 35

Trevor Elliott
Trevor Elliott

Reputation: 11252

First of all, I hope you realize this shouldn't stop you since you can easily add any file you want to a project, either from your file system or by copying it from another project. The Add New Item window is just for convenience.

Secondly, when you added the new project to your solution, which project template did you choose? The project template determines the initial set of referenced assemblies that project has. A WPF project makes references to the WPF libraries (WindowsBase, PresentationCore, etc.).

Visual Studio uses your referenced assemblies to generate the possible items you see in the Add New Items dialog.

So I'm assuming you added some other type of project, such as a basic Class Library. You could manually add the references to the WPF assemblies using the Add Reference dialog. Or you could re-create the project as a WPF Custom Control Library.

Upvotes: 5

Related Questions