MVP 监督控制器、数据绑定和撤消/重做
我的应用程序是 MDI Winform 应用程序。 我遇到一些与 MVP 模式和数据绑定相关的问题。
我所有的形式都是无模式的。当我修改字段或更改组合框中的选定项目时,我想修改模型,并且希望所有表单立即与模型同步。 数据绑定非常适合简单的字段,而对于复杂的操作,我使用 Presenter 来“手动”更新视图。
但是,如何将撤消/重做机制放入图片中? 我的意思是:我想通过单击“撤消”按钮来恢复在文本字段中所做的更改。
我尝试应用命令模式,但似乎在数据绑定机制中没有地方引入“命令”机制。我对此深感困扰,以至于我现在正在考虑完全放弃绑定机制。
我看到了很多关于Binding的文章,但没有真正公开撤消/重做的解决方案。
撤消/重做和数据绑定真的不兼容吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用受监控的撤消框架( http://muf.codeplex.com/ 或 NuGet 等库) 来管理撤消堆栈。它不需要命令模式。相反,您监视模型的更改,然后将这些更改推送到撤消堆栈中。撤消更改意味着从堆栈中提取先前的值并将其推回到模型中。
该库是为 WPF 编写的,但如果您正确设置了绑定,它也应该适用于 WinForms。此外,您可以在模型中挂钩回调,以便您知道值何时因撤消/重做操作而更改。
该库包含文档、单元测试以及一些示例的链接,展示了如何使用它。
You could use a library like the Monitored Undo Framework ( http://muf.codeplex.com/ or on NuGet) to manage the undo stack. It doesn't require the Command pattern. Instead, you monitor changes to your model and then push those changes into the undo stack. Undo a change means pulling the prior value from the stack and pushing it back into the model.
The library was written for WPF, but if you have your bindings setup properly, it should also work for WinForms. Additionally, you can hook callbacks in the model so that you know when a value has changed due to an undo / redo operation.
The library has documentation, unit tests, and links to some samples showing how to use it.