Hello!
I think that this is the compatibility bug. (.NetCore 3.0 preview8)
Build and run the code below at the ,Net Framework and at the .Net Core platforms and we will see a difference.
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestApp {
class Program {
public class MainObject : INotifyPropertyChanged {
private string text;
public string Text {
get { return text; }
set {
if(text != value) {
text = value;
if(PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Text)));
}
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public bool IsPropertyChangedAssigned { get { return PropertyChanged != null; } }
}
static void Main(string[] args) {
MainObject mainObject = new MainObject();
mainObject.Text = "Test text";
Form form = new Form();
TextBox textBox = new TextBox();
Binding binding = new Binding("Text", mainObject, "Text");
textBox.DataBindings.Add(binding);
textBox.Parent = form;
form.Show();
Console.WriteLine("MainObject.IsPropertyChangedAssigned: {0}", mainObject.IsPropertyChangedAssigned);
textBox.DataBindings.Clear();
binding = null;
Console.WriteLine("MainObject.IsPropertyChangedAssigned: {0}", mainObject.IsPropertyChangedAssigned);
Console.ReadLine();
}
}
}
For .Net Framework the result is:
MainObject.IsPropertyChangedAssigned: True
MainObject.IsPropertyChangedAssigned: False
For .Net Core the result is:
MainObject.IsPropertyChangedAssigned: True
MainObject.IsPropertyChangedAssigned: True
The PropertyChanged event subscription remains after binding remove.
Thanks,
Nat.
Hello!
I think that this is the compatibility bug. (.NetCore 3.0 preview8)
Build and run the code below at the ,Net Framework and at the .Net Core platforms and we will see a difference.
For .Net Framework the result is:
MainObject.IsPropertyChangedAssigned: True
MainObject.IsPropertyChangedAssigned: False
For .Net Core the result is:
MainObject.IsPropertyChangedAssigned: True
MainObject.IsPropertyChangedAssigned: True
The PropertyChanged event subscription remains after binding remove.
Thanks,
Nat.