c# - 在 MVVM 中,为什么人们要创建 ViewModel 文件夹?

标签 c# .net mvvm

...而不是使用 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/

相关文章:

c# - 图表控件 : Stacked Column Series Label Positioning

c# - 不使用 AJAX AutoCompleteExtender 和 Web 服务的 ASP.Net 中的自动完成文本框

WPF:如何在代码隐藏中不使用代码的情况下从 ViewModel 向 View 发出事件信号?

ios - 在 MVVM 和 RxSwift 中围绕 ViewController 传递数据

c# - ASP.NET MVC 项目构建在 travis-ci 上开始失败

c# - Cyber​​Source 简单订单 API 捕获 PayPal 交易

C# DateTime - 如何检查时间部分是否为 NULL?

c# - 如何协调 LINQ 中的第一条和最后一条记录

.net - System.Net.Mail.MailAddress'解析器接受的格式是什么?

silverlight - 如果支持 VM 的 props 的每个字段都实现 INotifyPropChange,VM 是否需要实现 INotifyPropChagned?