WPF中如何实现多个TextBox和数组的绑定
请教:WPF中如何实现多个TextBox和数组的绑定。
我以前的做法是把TextBox做成控件数组,但是现在想用WPF的Binding,一对一的绑定我知道,但是这种绑定数组的却没弄明白。
变量是单独建了个类存放的,像这样:
public class Student:INotifyPropertyChanged
{
private string name;
public string Name
{
set
{
name = value;
NotifyPropertyChanged("Name");
}
get { return name; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
}
}
}
绑定使用代码写的,像这样:
public MainWindow()
{
InitializeComponent();
student = new Student();
Binding binding = new Binding();
this.TextBox1.SetBinding(TextBox.TextProperty, new Binding("Name") { Source = student });
}