不实现 INotifyPropertyChanged接口也能实现数据绑定

今天学习了一下WPF的数据绑定。

我自定义了一个类,只有一个属性,如下:

public class test
{
    string Content { get; set; }
}

在窗体的XAML文件中,添加2个Textbox控件,将Text属性绑定到DataContext,如下:

<TextBox Name="textbox1" Text="{Binding Path=Content, Mode=TwoWay}" />
<TextBox Name="textbox2" Text="{Binding Path=Content, Mode=TwoWay}" />

在窗体的构造函数中添加绑定,如下:

public MainWindow()
{
    InitializeComponent();
    
    this.textbox1.DataContext = this.test;
    this.textbox2.DataContext = this.test;
}

如此即可实现数据绑定,请大家帮忙解释一下和实现INotifyPropertyChanged的区别。

原文地址:https://www.cnblogs.com/ljyuma/p/3384494.html