简体   繁体   English

Winforms双向数据绑定将无法正确更新UI,除非执行其他一些UI操作

[英]Winforms two-way data binding won't update UI properly unless doing some other UI operations

I'm debugging an old winform that uses two-way data binding under VS2017. 我正在调试在VS2017下使用双向数据绑定的旧winform。

As for two-way binding, I used the following code: 至于双向绑定,我使用了以下代码:

var bs = new BindingSource(components) {DataSource = model};                    
_destinationComboBox.DataSource = model.GetDestination();
            _destinationComboBox.DataBindings.Add(new Binding("SelectedItem",
                                                              bs.DataSource,
                                                              "Destination", true,
                                                              DataSourceUpdateMode.OnPropertyChanged));

The model has properly implemented INotifyPropertyChanged .Everything is good, but the GUI only updates after properties changed when I, for instance, switching tabs or click some buttons(perform some other UI operations). 该模型已正确实现了INotifyPropertyChanged一切都很好,但是GUI仅在属性更改后(例如,切换选项卡或单击某些按钮(执行一些其他UI操作))才更新。

The problem is very confusing and hard to debug. 这个问题非常令人困惑,难以调试。

I finally found out that the VS2017(at least under 15.9.11) debugger has something to do with this. 我终于发现VS2017(至少在15.9.11以下)调试器与此有关。 After detaching the debugger, the GUI updates once properties change, just as expected. 分离调试器后,GUI会在属性更改后立即更新,正如预期的那样。

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

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