13

如何将我的 ViewModel 文件(一个 .cs 文件)折叠在其对应的视图文件(一个 .xaml 文件)文件中,就像在图像中一样?

在此处输入图像描述

4

1 回答 1

17

我不知道在 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>
于 2011-02-27T05:10:03.787 回答