DataGrid myGrid = new DataGrid(); CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView(myGrid.Items); ((INotifyCollectionChanged)myCollectionView).CollectionChanged += new NotifyCollectionChangedEventHandler(DataGrid_CollectionChanged);
另一种方式
var dpd = DependencyPropertyDescriptor.FromProperty(ItemsControl.ItemsSourceProperty, typeof(DataGrid)); if (dpd != null) { dpd.AddValueChanged(myGrid, ThisIsCalledWhenPropertyIsChanged); } private void ThisIsCalledWhenPropertyIsChanged(object sender, EventArgs e) {
//搞事 }