【问题标题】:How can I fold .cs files inside .xaml files in Visual Studio 2010?如何在 Visual Studio 2010 的 .xaml 文件中折叠 .cs 文件?
【发布时间】:2011-07-05 03:06:30
【问题描述】:

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

【问题讨论】:

    标签: visual-studio xaml computer-science folding


    【解决方案1】:

    我不知道在 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>
    

    这两个标签在您的文件中可能不相邻。重要的部分是&lt;DependantUpon&gt; 标签。

    在您的文件中,找到具有include="ViewModel.cs" 属性的标签。在此标记内,添加 &lt;DependantUpon&gt;View.xaml&lt;/DependantUpon&gt; 作为子元素。现在,您的 ViewModel.cs 文件将始终位于 View.xaml 文件中。最后,你的文件应该有这些类似于这个 sn-p 的东西:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-01
    相关资源
    最近更新 更多