1

My application is a MDI Winform application. I encounter some problems connected with MVP pattern and Data Bindings.

All my forms are modeless. When I modify a field, or change the selected item in a combobox, I want to modify the model and I want all the form (s) to synchronize immediately with the model. Databinding allow this perfectly for simple fields ,and for complex operations , I use the Presenter to update view "manually" .

But, How to put Undo/redo mechanisms in the picture ? I mean: I want to revert change I made in a text field by clicking an "undo" button.

I try to apply command pattern, but it seems there is no place to introduce a "command" mechanism in the databinding mechanism. I'm so stuck with this , that I now take under consideration to abandon Binding mechanisms completely.

I see so many articles about Binding, but no solution to undo/redo is really exposed.

Are undo/redo and databinding really uncompatible?

4

1 回答 1

0

您可以使用 Monitored Undo Framework(http://muf.codeplex.com/或 NuGet 上)之类的库来管理撤消堆栈。它不需要命令模式。相反,您监控模型的更改,然后将这些更改推送到撤消堆栈中。撤消更改意味着从堆栈中拉出先前的值并将其推回模型中。

该库是为 WPF 编写的,但如果您的绑定设置正确,它也应该适用于 WinForms。此外,您可以在模型中挂钩回调,以便您知道何时由于撤消/重做操作而更改了值。

该库有文档、单元测试和一些示例的链接,展示了如何使用它。

于 2011-07-01T18:16:22.447 回答