【WPF】binding的使用

来源:互联网 发布:围棋软件形势判断 编辑:程序博客网 时间:2024/04/30 10:58
Binding bd = new Binding();bd.Source = MItem;bd.Mode = BindingMode.TwoWay;bd.Path = new PropertyPath("ParameterValue");BindingOperations.SetBinding(textBox1,TextBox.TextProperty, bd); //这样在修改MItem.ParameterValue的值时,textBox1将自动更新数据public class MonitorItem:INotifyPropertyChanged    {        public event PropertyChangedEventHandler PropertyChanged;        private void SetProprty(string PropertyName)        {            if (this.PropertyChanged != null)            {                this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));            }        }        public MonitorItem()        {                    }        private string _ParameterName = "";        public string ParameterName        {            set            {                _ParameterName = value;                SetProprty("ParameterName");            }            get            {                return _ParameterName;            }        }}


 

原创粉丝点击