visual-studio-2012 - 将现有的XAML文件添加到Visual Studio 2012

标签 visual-studio-2012 code-behind

我想将包含xaml和CS文件以及其他目录的文件夹添加到VS上的其他项目。由于某些原因,当我将文件夹从Windows资源管理器拖到项目时,我想将该目录放置在Visual Studio中。因此,我要手动添加每个文件,每次遇到目录时都必须创建一个文件。也许是因为我正在使用团队基础服务器。

无论如何,我都是手动添加文件,所以我在Visual Studio上单击要添加文件的文件夹,然后单击“添加现有文件”。然后,选择xaml并在文件后面添加代码:

当我单击“添加”时,文件被添加,但是Visual Studio无法识别Bytes.xaml.cs是背后的代码!

我是否必须手动添加一个窗口,然后复制并粘贴文件的内容?

最佳答案

编辑您的.csproj文件,以在.xaml.cs文件的“编译”元素下方添加一个“DependentUpon”元素,以使其出现在.xaml文件“内部”,而不仅仅是在其下方。:

<Compile Include="BytesDisplay\SubControls\Bytes.xaml.cs">
  <DependentUpon>Bytes.xaml</DependentUpon>
</Compile>

要轻松编辑.csproj文件,请执行以下操作:
Right-click the project and select "Unload Project"
Right-click the project node again and select "Edit [projectname].csproj"
Edit the XML, then close the file
Right-click the project node again and select "Reload Project"

关于visual-studio-2012 - 将现有的XAML文件添加到Visual Studio 2012,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13387527/

相关文章:

c# - 没有代码隐藏的 ASP.net 页面

c++ - 如何在 Visual Studio 2012 中设置资源编辑器的网格大小?

c++ - 无法同时使用C++ Rest SDK和微软单元测试

asp.net - jquery追加+代码隐藏

c# - 以编程方式添加 span 标记,而不是 Label 控件?

.net - ASP.NET Web 表单 HTML 标记中的自定义属性

sql - ssdt 部署后脚本运行一次

c++ - Visual Studio 11 图形调试器的目标应用程序要求

windows - 尝试在 Visual Studio 2012 中添加对项目的引用, "no items found"

javascript - ASP.NET 代码隐藏文件在哪里执行? (客户端或服务器)