/// <summary> /// Called whenever a model element is deleted from the store. /// </summary> /// <param name="sender">ViewModelStore</param> /// <param name="args">Event Arguments for notification of the removal of an ModelElement.</param> private void OnElementDeleted(object sender, ElementDeletedEventArgs args) { if (args.ModelElement is DomainModelElement) { DomainModelElement modelElement = args.ModelElement as DomainModelElement; List <Guid> shapes = GraphicalDependencyShapeStore.GetFromStore(modelElement.Id); if (shapes != null) { if (shapes.Count > 0) { modelElement.Store.UndoManager.UndoState = UndoState.DisabledNoFlush; using (Transaction t = modelElement.Store.TransactionManager.BeginTransaction("", true)) { for (int i = shapes.Count - 1; i >= 0; i--) { ShapeElement shape = modelElement.Store.ElementDirectory.FindElement(shapes[i]) as ShapeElement; if (shape != null) { shape.Delete(); } } t.Commit(); } modelElement.Store.UndoManager.UndoState = UndoState.Enabled; GraphicalDependencyShapeStore.RemoveFromStore(modelElement.Id); } } } }
/// <summary> /// Called whenever a model element is beeing deleted. /// </summary> /// <param name="e"></param> public override void ElementDeleting(ElementDeletingEventArgs e) { base.ElementDeleting(e); DomainModelElement modelElement = e.ModelElement as DomainModelElement; if (modelElement == null) { return; } List <Guid> shapes = GraphicalDependencyShapeStore.GetFromStore(modelElement.Id); if (shapes != null) { modelElement.Store.UndoManager.UndoState = UndoState.DisabledNoFlush; using (Transaction t = modelElement.Store.TransactionManager.BeginTransaction("", true)) { for (int i = shapes.Count - 1; i >= 0; i--) { ShapeElement shape = modelElement.Store.ElementDirectory.FindElement(shapes[i]) as ShapeElement; if (shape != null) { shape.Delete(); } } t.Commit(); } modelElement.Store.UndoManager.UndoState = UndoState.Enabled; } }