bindingsource属性setter两次调用为什么? [英] bindingsource property setter called twice why?

查看:67
本文介绍了bindingsource属性setter两次调用为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个Checkbox,巫婆检查属性绑定到单个对象的布尔属性。更新模式设置为OnPropertychanged,因为不需要验证,我不希望用户必须单击其他位置或按Tab键提交此类更改。



问题是BindingSource在复选框失去焦点后第二次调用对象的属性setter就像更新模式是OnValidation一样!这会导致我的应用程序出现混乱...



该对象实现了INotifyPropertyChanged,但我删除了对我的帮助器方法的调用,该方法引发了PropertyChanged事件以查看是否存在这是双重呼叫的原因,但事实并非如此。



我只是不明白!为什么那种行为?

解决方案

请看我对这个问题的评论。



这些问题很容易解决使用调试器的一个很棒的工具:调用堆栈窗口。如果您使用Visual Studio,请使用[主菜单] D ebug => W indows => C 所有Stack,以及属性setter处的断点。堆栈将显示呼叫在第一位和其他情况下的位置。



-SA


< blockquote>我总是广泛使用所有调试功能和逻辑来跟踪这些问题,除非我关闭只是我的代码并深入研究调试输出显示的内容,否则调用堆栈无济于事。它有时可以帮助我自己的代码找到错误,但并不总是如此。



我用我讨厌的那种愚蠢的解决方法解决了这个问题;通过将value与类的属性的Private Field进行比较来修改我的属性setter,以忽略不需要的调用,它就像预期的那样工作。



我无法想象没有数据绑定工作但我经常不得不面对绑定源组件这样的情况。


I a have a Checkbox on my form witch checked property is bound to a single object's boolean property. The update mode is set to OnPropertychanged cause there's no need for validation and i don't want the user having to click else where or press tab to commit that kind of change.

The problem is that the BindingSource calls the object's property setter a second time right after the checkbox looses focus just as if the update mode was OnValidation! That cause a terrible mess in my application...

The object implements the INotifyPropertyChanged but i removed the call to my helper method that raise the PropertyChanged event to see if that was the cause of that double call and it's not.

I just don't get it! why that behavior?

解决方案

Please see my comment to the question.

Such problems are easily resolved using the debugger with one of its wonderful tools: "Call Stack" window. If you use Visual Studio, use [main menu] Debug => Windows => Call Stack, and a breakpoint at the property setter. The stack will show you where the call comes at first place and other cases.

—SA


I always make extensive use of all debugging features and logic to track problems like these, the call stack does not help unless i turn "just my code" off and dive into that stuff the debug output shows me. It sometimes help find errors in my own code but not always.

I solved this issue with that stupid kind of workaround i hate; by modifying my property setter in a way to ignore the unwanted call by comparing "value" with the Private Field of the class's property and it work like a expected.

I Just can't imagine working without Data Bindings but i frequently have to face situations like this with the bindingsource component.


这篇关于bindingsource属性setter两次调用为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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