How can I fold .cs files inside .xaml files in Visual Studio 2010?

Deadly 提交于 2019-12-19 05:14:09

问题


How can I put my ViewModel file (a .cs file) folded inside its corresponded View file (a .xaml file) file like in the image?


回答1:


I don't know of a way to do it in visual studio, but you can edit your .csproj file in a text editor. You should find something like this:

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

The two tags might not be right next to each other in your file. The important part is the <DependantUpon> tag.

In your file, find the tag with the include="ViewModel.cs" attribute. Inside of this tag, add <DependantUpon>View.xaml</DependantUpon> as a child element. Now your ViewModel.cs file will always be a inside the View.xaml file. In the end, your file should have these something similar to this snippet:

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


来源:https://stackoverflow.com/questions/5131526/how-can-i-fold-cs-files-inside-xaml-files-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!