Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 423
Cuero Avatar asked Sep 24 '12 02:09

Cuero


People also ask

How to add ResourceDictionary in WPF?

Adding a resource dictionary is pretty simple. We have to select the project or folder in Solution Explorer and then right click and select “Add”. We will get a menu item called “Resource Dictionary”. Clicking on that menu item will popup up the Add New Item wizard with the Resource Dictionary Item template selected.

How to add a resource dictionary?

Tip You can create a resource dictionary file in Microsoft Visual Studio by using the Add > New Item… > Resource Dictionary option from the Project menu. Here, you define a resource dictionary in a separate XAML file called Dictionary1.

What is Resourcedictionary?

A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.


2 Answers

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.

like image 186
MatrixManAtYrService Avatar answered Nov 25 '22 10:11

MatrixManAtYrService


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.

like image 44
Trevor Elliott Avatar answered Nov 25 '22 09:11

Trevor Elliott