如何在Visual Studio 2010中折叠.xaml文件中的.cs文件?

时间:2011-02-27 04:50:28

标签: visual-studio xaml computer-science folding

如何将我的ViewModel文件(.cs文件)折叠在其对应的View文件(.xaml文件)文件中,如图像中所示?

enter image description here

1 个答案:

答案 0 :(得分:18)

我不知道如何在visual studio中进行此操作,但您可以在文本编辑器中编辑.csproj文件。你应该找到这样的东西:

<Page Include="MainWindow.xaml">
  <Generator>MSBuild:Compile</Generator>
  <SubType>Designer</SubType>
</Page>
<Compile Include="MainWindow.xaml.cs">
  <DependentUpon>MainWindow.xaml</DependentUpon>
  <SubType>Code</SubType>
</Compile>

文件中的两个标签可能并不紧挨着。重要的部分是<DependantUpon>标记。

在您的文件中,找到包含include="ViewModel.cs"属性的标记。在此标记内,添加<DependantUpon>View.xaml</DependantUpon>作为子元素。现在,您的ViewModel.cs文件将始终位于View.xaml文件中。最后,您的文件应该具有与此代码段相似的内容:

<Page Include="View.xaml">
  <SubType>Designer</SubType>
  <Generator>MSBuild:Compile</Generator>
</Page>
<Compile Include="ViewModel.cs">
  <DependentUpon>View.xaml</DependentUpon>
</Compile>
相关问题