MVP 监督控制器、数据绑定和撤消/重做

发布于 2024-10-21 09:38:13 字数 374 浏览 2 评论 0原文

我的应用程序是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃梦幻 2024-10-28 09:38:13

您可以使用受监控的撤消框架( 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文