本文介绍了bindingsource属性setter两次调用为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的表单上有一个Checkbox,巫婆检查属性绑定到单个对象的布尔属性。更新模式设置为OnPropertychanged,因为不需要验证,我不希望用户必须单击其他位置或按Tab键提交此类更改。 问题是BindingSource在复选框失去焦点后第二次调用对象的属性setter就像更新模式是OnValidation一样!这会导致我的应用程序出现混乱... 该对象实现了INotifyPropertyChanged,但我删除了对我的帮助器方法的调用,该方法引发了PropertyChanged事件以查看是否存在这是双重呼叫的原因,但事实并非如此。 我只是不明白!为什么那种行为?解决方案 我总是广泛使用所有调试功能和逻辑来跟踪这些问题,除非我关闭只是我的代码并深入研究调试输出显示的内容,否则调用堆栈无济于事。它有时可以帮助我自己的代码找到错误,但并不总是如此。 我用我讨厌的那种愚蠢的解决方法解决了这个问题;通过将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? 解决方案 这篇关于bindingsource属性setter两次调用为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 12:11