4

我目前正在开发一个棕地应用程序,它是用 winforms 编写的,作为在更高版本中使用 WPF 的准备,团队计划至少使用 MVVM/Presentation 模型,并将其与 winforms 绑定......

我已经探索了这个主题,包括这个网站上的帖子(我非常喜欢),归结为 wpf 的主要优点是:

  • 将控件绑定到 xaml 中的属性。
  • 将命令绑定到视图模型中的命令对象。

第一个功能很容易实现(在代码中),或者使用通用控件绑定器,它绑定了表单中的所有控件。

第二个功能实现起来有点困难,但是如果您从所有控件继承并添加一个命令属性(由单击等内部事件触发),该属性将绑定到 ViewModel 中的命令实例。

我目前知道的挑战是:

  • 实现一个命令管理器,(这将根据需要触发命令的 CanInvoke 方法。
  • winforms 只支持一级数据绑定:datasource、datamember,wpf 更加灵活。

在尝试实现这种设计模式时,我是否遗漏了 winforms 与 wpf 相比缺乏的任何其他主要功能?

我相信你们中的许多人会推荐某种 MVP 模式,但 MVVM/Presentation 模型是我的选择,因为我需要未来的 WPF 支持。

在此先感谢,埃里克。

4

2 回答 2

1

您可能会发现WAF Windows 窗体适配器很有趣。它展示了如何在 Windows 窗体应用程序中应用模型-视图-视图模型 (MVVM) 模式。适配器实现为Windows 窗体中缺少的命令支持提供了解决方案。

于 2010-09-20T18:10:57.310 回答
1

Please take a look at Update Controls .NET. It is an open-source library for Winforms, WPF, and Silverlight that keeps controls up to date as data changes. You can start using it now for Winforms, and then transition over to WPF without changing your Data Model or View Model code.

Unfortunately, it does not solve the Winforms command binding problem. Your button click events will not port from Winforms to WPF. But it does take care of the data binding problem.

于 2009-09-28T21:09:17.487 回答