question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Control DataBindings do not update when using INotifyPropertyChanged.

See original GitHub issue
  • .NET Core Version: 3.0.100-preview3-010431
  • Have you experienced this same bug with .NET Framework?: No

Problem description: Control bound to a property does not update when INotifyPropertyChanged is triggered. The same code works in Windows Forms on .Net Framework. Repro example below is for a label, but also tried with a button and saw the same issue.

Actual behavior: Bound control is not updated when the property is updated.

Expected behavior: Bound control should be updated when the property is updated.

Minimal repro:

  • Repro zipped for dowload here, includes projects for WinForms (Net Framework), WinForms (Net Core), and WPF (Net Core).

  • Create a Windows Forms (.Net Core) application.

  • Add a class with a property to bind to, example below:

public class TestController : INotifyPropertyChanged
    {
        private string simpleStringProperty;

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

        public TestController()
        {
            SimpleStringProperty = "hi";
        }

        public string SimpleStringProperty
        {
            get => simpleStringProperty;
            set
            {
                simpleStringProperty = value;
                OnPropertyChanged(nameof(SimpleStringProperty));
            }
        }
    }
  • Add code to form1 ctor
            _controller = new TestController();
            label1.DataBindings.Add("Text", _controller, nameof(_controller.SimpleStringProperty));
  • Add a button and add following code to Click handler
_controller.SimpleStringProperty = "hello";
  • Run the application. The label is set to the initial value of SimpleStringProperty, but when the button is clicked, the value is not updated.

  • To compare to Windows Forms, carry out the above steps on a Windows Forms (.Net Framework) application and when the button is clicked, the label will update.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
merriemcgawcommented, Apr 17, 2019

Great! Closing the issue in that case 😃

0reactions
AlanParrcommented, Apr 11, 2019

I submitted a PR to dotnet/corefx#34465 to fix this which was merged yesterday

I’ve tested my original repro against Winforms and WPF for both .Net Core and .Net Framework and behaviour now appears to be identical.

Unless anyone else wants to verify, I think this issue can be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Control not immediately updating bound property with ...
I have controls which are not updating their bound object's respective properties until focus is lost. There are similar questions with accepted ...
Read more >
How to: Raise Change Notifications Using a ...
Learn how to raise change notifications using a BindingSource and the INotifyPropertyChanged Interface.
Read more >
Databindings not updating when property changes
Hi, I'm using a XtraEditor on a form that is layed out using the Layout Control. I have a Binding Source on the...
Read more >
C# WPF Tutorial #8 - Data Bindings using ... - YouTube
Learn how to logically separate your GUI and business logic by using data bindings and the interface INotifyPropertyChanged.
Read more >
WPF INotifyPropertyChanged and Databinding - YouTube
WPF INotifyPropertyChanged and Databinding what is the INotifyPropertyChanged interface and databinding in wpf how do I databind using wpf ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found