如何防止绑定触发 TextChanged 事件?
我使用 Control.TextChanged 事件来检测用户何时修改了表单。我有一个方法可以循环遍历每个控件并向所有控件添加相同的 TextChanged。
我的问题是,在表单上我还有数据绑定,它绑定具有 Binding.Format() 和 Binding.Parse() 的绑定,并且这些绑定位于 TabControl 内。如果用户更改选项卡 (SelectedIndexChanged),它就会激活 Format/Parse 并触发 TextChanged 事件,这使得表单看起来像是已被修改!
我怎样才能(1)保持绑定或 Binding.Format 和 .Parse 不触发 TextChanged 事件,或者(2)实现更好的方法来检测表单上的控件是否已被修改?
I'm using the Control.TextChanged event to detect when the user has modified the form. I have a method that loops through every control and adds the same TextChanged to all the controls.
My problem is, on the form I also have databinding that binds bindings that have Binding.Format() and Binding.Parse(), and these are within a TabControl. If the user changes tabs (SelectedIndexChanged), it then activates the Format/Parse and fires the TextChanged event which makes it seem like the form's been modified!
How can I either (1) keep the bindings or Binding.Format and .Parse from firing the TextChanged event, or (2) implement a better way to detect of the controls on the form have been modified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要检查实际的
TextChanged
事件,而是检查支持属性并查看它们何时发生更改。您可以使用 INotifyPropertyChanged 来帮助解决此问题。Instead of checking the actual
TextChanged
Event, check the backing properties and look at when they change. You can make use ofINotifyPropertyChanged
to help out with this.