更新时间:2022-02-14 03:24:42
我不知道在Visual Studio中执行此操作的方法,但是您可以在文本编辑器中编辑.csproj文件.您应该会找到类似这样的内容:
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>
这两个标记在文件中可能并不紧邻.重要的部分是<DependantUpon>
标记.
The two tags might not be right next to each other in your file. The important part is the <DependantUpon>
tag.
在文件中,找到具有include="ViewModel.cs"
属性的标签.在此标记内,添加<DependantUpon>View.xaml</DependantUpon>
作为子元素.现在,您的ViewModel.cs文件将始终位于View.xaml文件中.最后,您的文件应具有与以下代码段相似的内容:
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>