WPF绑定 [英] WPF Binding

查看:144
本文介绍了WPF绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用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.

推荐答案

使用 Memento模式 [ ^ ],您可以轻松地允许用户放弃对对象所做的更改.

希望这会有所帮助,
弗雷德里克(Fredrik)
Using the Memento Pattern[^] you can easily allow the user to discard the changes made to an object.

Hope this helps,
Fredrik


这篇关于WPF绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆