以下摘自this article在 MVVM 上。有人可以提供这些其他模式(命令、DI)如何在 WPF 中使用的示例吗? WPF 中是否还有其他您未在此处列出的设计模式?
There are other patterns you should be aware of to assist you in MVVM. Patterns like commanding (baked into WPF, solutions for SL), mediator and gasp dependency injection. .
请您参考如下方法:
我写过关于其中一些的文章:WPF and Silverlight design patterns
以下是模式的简要说明:
1) MVVM - 用作模型转换器和代码隐藏的替代品。提高可测试性,为 ViewModel 编写单元测试要容易得多。
2) 依赖注入(inject) - 用于提高类的可测试性(您可以为特定类与其他类分开编写单元测试)以及以更简单的方式更改实现的可能性(更改记录器、缓存提供程序、Web 服务等)
3) 命令 - 默认情况下可以应用于 Button 和 MenuItem 控件,如果无法执行操作,则禁用控件。也用于 MVVM 模式作为代码隐藏事件的替代。
经典书籍中已在 WPF 中使用的其他模式:
在 Web 表单中。
为 UI 转换绑定(bind)值的接口(interface)。
具有可变厚度和颜色的边框。
使您能够使用整个打印和文档子系统
WPF 提供的。
RoutedCommand 和 RoutedUICommand 类。
在 .NET Framework 中实现。


