WPF取消双向绑定 [英] WPF cancelling twoway binding

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

问题描述

你好,

我有一个ListBox,其名称和地址显示在数据模板中.当我选择一个项目时,它会打开一个包含其他信息的编辑表单.我正在使用双向绑定,并设置了UpdateSourceTrigger=PropertyChanged.
我在编辑表单上有一个保存和取消按钮. save事件将更改持久保存到数据库.(对SQL的linq)

如果不想保留更改,如何获取取消事件以撤消在编辑表单中所做的更改?现在,如果我选择取消"并显示我的列表框表单.显示更改.
我的第二个难题是.我在编辑表单上有验证.但是,即使更改违反了验证规则,更改仍然会更新源.我尝试设置UpdateSourceTrigger=Explicit.完成时.用户界面上的错误不起作用,例如,我可以清除名称字段,并且不会显示任何通知.设置UpdateSourceTrigger=PropertyChanged时不是这种情况.
欢迎您的帮助
谢谢

Hello,

I have a ListBox with the name and address of my customers displayed in a data template. When I select an item it opens an edit form with other information. I am using two-way binding and have set the UpdateSourceTrigger=PropertyChanged.
I have a save and cancel button on the edit form. The save event persist the changes to the database.(linq to SQL)

How can I get the cancel event to undo the changes I have made in the edit form if I do not want to persist the changes? As it is now if I select cancel and display my listbox form. The changes are displayed.
My second dilemma is. I have validation on the edit form. However the changes still update the source even if it violates the validation rule. I tried setting the UpdateSourceTrigger=Explicit. When this was done. The errors on the UI were not working, E.g., I could clear the name field and no notification will show. This was not the case when I set UpdateSourceTrigger=PropertyChanged.
I welcome you help
Thanks

推荐答案

更改触发器以将其绑定到内部bool属性的状态,该状态指示用户是否单击了正常按钮.
Change the trigger to bind to the state of an internal bool property that indicates whether or not the user clicked okay or not...


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

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