我想将包含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/