将 NumericUpDown 控件绑定到实现 INotifyPropertyChanged 的​​对象

发布于 2024-12-12 18:07:08 字数 450 浏览 7 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绅士风度i 2024-12-19 18:07:08

我在使用 时遇到了类似的问题WriteValue 函数

numericUpDown.DataBindings["Value"].WriteValue();

当控件失去焦点之前不写入值时,此函数有效。

I've had a similar problem where I used the WriteValue function

numericUpDown.DataBindings["Value"].WriteValue();

This worked when it wasn't writing the value until the control lost focus.

人心善变 2024-12-19 18:07:08

numericUpDown.DataBindings["Value"].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

numericUpDown.DataBindings["Value"].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文