简体   繁体   English

目标仅更新一次

[英]Target is Only Updating Once

My main form has tabs (a TabControl) and my target control (a TextBox) is in the third tab. 我的主窗体有选项卡(一个TabControl),目标控件(一个TextBox)在第三个选项卡中。 On the first tab, I have several TextBox controls where I enter data. 在第一个选项卡上,我有几个在其中输入数据的TextBox控件。 My code parses the data entered and determines the maximum value, which it stores in a property that is bound to my target TextBox. 我的代码解析输入的数据并确定最大值,并将其存储在绑定到目标TextBox的属性中。

textBox_Offset_ODR_MaxDepth.DataBindings
                           .Add("Text", kernel.Targets, Targets.MaxDepthName);

When I run the program, I add data on my first tab, look at my third tab, and then see that the TextBox has been updated properly. 运行程序时,我在第一个选项卡上添加数据,在第三个选项卡上查看,然后查看TextBox是否已正确更新。 It shows the maximum value correctly. 它正确显示最大值。 So then I go back to my first tab, change the data, and then look at my third tab again. 因此,我回到第一个选项卡,更改数据,然后再次查看我的第三个选项卡。 The value has not been updated. 该值尚未更新。

I can see from other controls that use the source property in calculations that the source property has indeed been updated, but that update hasn't been pushed to the target TextBox. 我可以从在计算中使用source属性的其他控件中看到,source属性确实已更新,但是该更新尚未推送到目标TextBox。

How can I get the TextBox to always update when the source property changes? 当source属性更改时,如何使TextBox始终更新?

I'll give my workaround as an answer to this with the hope that I'll help someone else, but it would be even better if someone could identify my problem and tell me what I'm doing wrong. 我将给出解决方法,以期希望对其他人有所帮助,但是如果有人能够识别出我的问题并告诉我我做错了那会更好。 I've been searching for several hours. 我已经搜寻了几个小时。

I added a "Refresh" Button and gave it this code: 我添加了一个“刷新”按钮,并为其提供了以下代码:

private void button_Offset_ODR_Refresh_Click(object sender, EventArgs e)
{
    textBox_Offset_ODR_MaxDepth.DataBindings[0].ControlUpdateMode = ControlUpdateMode.Never;
    textBox_Offset_ODR_MaxDepth.DataBindings[0].ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;
}

At some point I had (for some strange reason) commented out my declaration of the INotifyPropertyChanged interface. 在某些时候(出于某种奇怪的原因)我注释掉了我对INotifyPropertyChanged接口的声明。

class Targets// : INotifyPropertyChanged

My class implemented the interface, but that declaration at the top had been commented out. 我的课程实现了该接口,但顶部的声明已被注释掉。 For some reason, this allows the target control to be updated only once. 由于某些原因,这使得目标控件只能更新一次。 When I removed the commenting 当我删除评论时

class Targets : INotifyPropertyChanged

it ran fine and updated the target control appropriately. 运行良好,并适当地更新了目标控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM