使用 MVVM/MVVM-Light 编辑记录

发布于 2024-10-05 04:25:23 字数 359 浏览 0 评论 0原文

我用 mvvm light 创建了一个非常简单的 wpf 应用程序。

我在列表视图中有行,这些是 Book 对象的模板化表示。 我可以单击一行,然后单击一个编辑按钮,该按钮加载一个新窗口并向新窗口发送要编辑的书籍(使用 mvvm-light 的 Messenger)。

我遇到的问题是,当我在新窗口中编辑记录时,主窗体上的数据会更新。文本框绑定到通过 Messenger 接收的对象。

我知道这是因为我基本上传递了对周围同一 Book 对象的引用,因此我在一个地方更新..瞧,它也在主页上更新。

我想知道的是..是否有一个标准的方式/方法/概念来实现我想要做的事情?即创建一个“编辑”页面/屏幕,并可以选择放弃编辑?

谢谢。

I have created a very simple wpf app with mvvm light.

I have rows in a list view, these are templated representations of Book objects.
I can click a row, then click an edit button, this button loads a new window and sends the new window the book to edit (using mvvm-light's Messenger).

The issue I have is when I edit the record in my new window the data on the main form is updated. The text boxes are bound to the object received via the Messenger.

I know this is because I have essentially passed a reference to the same Book object around the place, therefore I update in one place.. and voilà it updates on the main page too.

What I would like to know is.. is there a standard way/method/concept to achieve what I am trying to do? i.e. create an "edit" page/screen with the option of discarding the edits?

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眼眸里的那抹悲凉 2024-10-12 04:25:23

您能让您的实体实现 ICloneable 并创建一个克隆以进行编辑吗?

Could you make your entity implement ICloneable and create a clone for editing?

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