12
如何將我的ViewModel文件(一個.cs文件)摺疊到其對應的View文件(.xaml文件)文件中,就像在圖像中一樣?如何在Visual Studio 2010中的.xaml文件中摺疊.cs文件?
如何將我的ViewModel文件(一個.cs文件)摺疊到其對應的View文件(.xaml文件)文件中,就像在圖像中一樣?如何在Visual Studio 2010中的.xaml文件中摺疊.cs文件?
我不知道的方式做到這一點在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>
見http://stackoverflow.com/questions/3621345/how-to-group-partial-class-files-in-solution- explorer-vs2010的GUI方式來做到這一點 – 2011-02-27 15:34:21
如果有一個默認的GUI方法仍然會很好。似乎從一開始就顯而易見。 – 2011-02-27 17:40:36