...而不是使用 xxx.xaml.cs 生成的文件?
开发人员正在 Views 文件夹中的 xaml 中创建一个 View 。 Visual Studio 在 xaml 文件下生成 xaml.cs 文件。但开发人员更喜欢创建一个新文件夹 ViewModel,并为每个 xxx xaml 文件创建一个 xxxViewModel.cs 文件。为什么不把xxx.xaml.cs文件中的这些ViewModel的内容全部搬走呢?
最佳答案
因为 xaml.cs 与 xaml( View )紧密耦合,这违背了模式设计。
请查看此链接,它很好地解释了模式:http://reedcopsey.com/2010/01/06/better-user-and-developer-experiences-from-windows-forms-to-wpf-with-mvvm-part-7-mvvm/ :
The ViewModel
- The ViewModel knows nothing about the View
- The ViewModel directly interacts with the Model, in order to expose it for data binding
- The ViewModel manages the Application-specific information
关于c# - 在 MVVM 中,为什么人们要创建 ViewModel 文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11557539/