在“添加新项目窗口”中找不到ResourceDictionary

时间:2022-12-30 20:39:23

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. 在“添加新项目窗口”中找不到ResourceDictionary

当我创建一个新的WPF项目时,我可以在Add New Item Window中找到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.

更新:该项目最初用于.net 3.5,但现在它还有.net 4.0的版本。这意味着同一个项目中有两个.sln文件(一个用于3.5,另一个用于4.0)。

2 个解决方案

#1


3  

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.).

其次,当您将新项目添加到解决方案时,您选择了哪个项目模板?项目模板确定项目具有的初始引用程序集。 WPF项目引用WPF库(WindowsBase,PresentationCore等)。

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

Visual Studio使用引用的程序集生成您在“添加新项”对话框中看到的可能项。

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.

所以我假设你添加了一些其他类型的项目,比如基本的类库。您可以使用“添加引用”对话框手动添加对WPF程序集的引用。或者您可以将项目重新创建为WPF自定义控件库。

#2


25  

Add the following line to Project.csproj

将以下行添加到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.

这篇文章很好地解释了为什么这有效。

#1


3  

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.).

其次,当您将新项目添加到解决方案时,您选择了哪个项目模板?项目模板确定项目具有的初始引用程序集。 WPF项目引用WPF库(WindowsBase,PresentationCore等)。

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

Visual Studio使用引用的程序集生成您在“添加新项”对话框中看到的可能项。

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.

所以我假设你添加了一些其他类型的项目,比如基本的类库。您可以使用“添加引用”对话框手动添加对WPF程序集的引用。或者您可以将项目重新创建为WPF自定义控件库。

#2


25  

Add the following line to Project.csproj

将以下行添加到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.

这篇文章很好地解释了为什么这有效。