joe
joe

Reputation: 1288

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.

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).

Upvotes: 1

Views: 76

Answers (1)

joe
joe

Reputation: 1288

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. After detaching the debugger, the GUI updates once properties change, just as expected.

Upvotes: 2

Related Questions