日期:2014-05-16  浏览次数:20800 次

关于C#里的数据绑定
我写了个winform程序 代码如下

public partial class Form1 : Form
    {
        Person person;
        public Form1()
        {
            InitializeComponent();
            person = new Person();
            person.Age = 111;
            textBox_age.DataBindings.Add("Text", person, "Age");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            person.Age = 123;
        }
    }
    class Person
    {
        public int Age { get; set; }
    }
我想现在在button事件里边改变Age的值后,界面上的textBox的值跟着同步改变,我的代码改如何改呢,实现双向绑定。
------解决方案--------------------
去实现INotifyPropertyChanged接口试试吧