2011-06-01 83 views

回答

0

見討論here,而這個解決方案:

private void OnRowEditEnding(object sender, DataGridRowEditEndingEventArgs e) 
{ 
    DataGrid dataGrid = sender as DataGrid; 
    if (e.EditAction == DataGridEditAction.Commit) { 
     ListCollectionView view = CollectionViewSource.GetDefaultView(dataGrid.ItemsSource) as ListCollectionView; 
     if (view.IsAddingNew || view.IsEditingItem) { 
      this.Dispatcher.BeginInvoke(new DispatcherOperationCallback(param => 
      { 
       // This callback will be called after the CollectionView 
       // has pushed the changes back to the DataGrid.ItemSource. 

       // Write code here to save the data to the database. 
       return null; 
      }), DispatcherPriority.Background, new object[] { null }); 
     } 
    } 
}