设置DataGrid CanUserAddRows="True",自动添加一行。
控制当前row为新增行时不能删除
IEditableCollectionView editableCollectionView = dgDrug.Items;
if (editableCollectionView.IsAddingNew)
return;
private void BtnDeleteDrug_Click(object sender, RoutedEventArgs e) { try { var entity = ((Button)sender).Tag as CoPaymentSchemeItemPriceEntity; if (entity == null || entity.EntityDataRow == null) return; IEditableCollectionView editableCollectionView = dgDrug.Items; if (editableCollectionView.IsAddingNew) return; ViewModel.Model.CoPaymentSchemeItemDrugPriceList.Remove(entity); } catch (PresentationException pex) { pex.Report(); } catch (Exception ex) { new PresentationException(ex).Report(); } }