【发布时间】:2011-05-15 08:43:01
【问题描述】:
我想通过单击按钮在我的 WPF DataGrid 中设置一个单元格。
我像这样填写 WPF DataGrid:
myDataGrid.ItemsSource = GetMyList();
DataGrid 设置为 autoGenerateColumns。我使用 mySql 选择获取我的列表。
我列表中的对象实现了INotifyPropertyChanged 接口。
在我的按钮上单击我这样做:
MyObject o = (MyObject)myDataGrid.SelectedItem;
o.Checkin = DateTime.Now; //set date on button click is what i want
数据已设置,但DataGrid 未更新其视图。为什么?
编辑:
我像这样实现INotifyPropertyChanged 接口:
private void NotifyPropertyChanged(String info) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public DateTime Checkin {
get {return this.checkin;}
set {
this.checkin= value;
NotifyPropertyChanged("Checkin");
}
}
}
【问题讨论】: