将 NumericUpDown 控件绑定到实现 INotifyPropertyChanged 的对象
我有一个 NumericUpDown 控件,它绑定到实现 INotifyPropertyChanged 的业务对象上的 int 属性。 NumericUpDown 控件的数据源更新模式设置为 OnPropertyChanged,并且控件的 ReadOnly 属性设置为 false。这按预期工作,但有一个例外:如果我在 NumericUpDown 控件的文本框部分中输入一个值,则该控件绑定到的属性的值不会更新,直到该控件失去焦点。
我的表单上有一个带有几个按钮的 ToolStrip。单击这些按钮不会导致 NumericUpDown 控件失去焦点,因此在通过单击这些按钮之一对业务对象执行任何操作之前,我调用 toolStrip.Focus() 以确保 NumericUpDown 的文本框部分中的值控制权已被推回到业务对象。这似乎对我有用,但我想知道这是否是 NumericUpDown 控件在这种情况下的预期行为,如果是,其他人如何解决这种情况?感谢您的反馈!
I have a NumericUpDown control that is bound to an int property on a business object which implements INotifyPropertyChanged. The Data Source Update Mode for the NumericUpDown control is set to OnPropertyChanged and the ReadOnly property of the control is set to false. This works as expected with one exception: if I enter a value into the textbox portion of the NumericUpDown control, the value of the property that the control is bound to doesn't get updated until the control loses focus.
I have a ToolStrip with several buttons on my form. Clicking on these buttons won't cause the NumericUpDown control to lose focus so before I do anything with my business object via one of these button clicks, I call toolStrip.Focus() to make sure that the value in the textbox portion of the NumericUpDown control has been pushed back to the business object. This seems to work for me but I'd like to know if this is the expected behavior of the NumericUpDown control in this scenario and, if so, how other people work around this situation? Thanks for your feedback!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在使用 时遇到了类似的问题WriteValue 函数
当控件失去焦点之前不写入值时,此函数有效。
I've had a similar problem where I used the WriteValue function
This worked when it wasn't writing the value until the control lost focus.
numericUpDown.DataBindings["Value"].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;
numericUpDown.DataBindings["Value"].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;