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;
}
}
}