public void OnItemsPasted(List <object> itemsToPaste, List <object> metaData, Point pastePoint, WorkflowViewElement pastePointReference) { if (this.ModelItem.ItemType == typeof(State)) { WorkflowViewElement view = VisualTreeUtils.FindVisualAncestor <WorkflowViewElement>(this); if (view != null) { StateContainerEditor container = (StateContainerEditor)DragDropHelper.GetCompositeView(view); container.OnItemsPasted(itemsToPaste, metaData, pastePoint, pastePointReference); } return; } if (itemsToPaste.Count == 1 && itemsToPaste.First() is Transition) { if (metaData == null || metaData.Count != 1 || !(metaData.First() is string)) { ShowMessageBox(SR.PasteTransitionWithoutDestinationState); return; } ModelItem destinationState = FindState(metaData.First() as string); if (destinationState == null) { ShowMessageBox(SR.PasteTransitionWithoutDestinationState); return; } this.PopulateVirtualizingContainer(destinationState); ModelItem[] selectedItems = this.Context.Items.GetValue <Selection>().SelectedObjects.ToArray(); string errorMessage; if (!CanPasteTransition(destinationState, out errorMessage, selectedItems)) { ShowMessageBox(errorMessage); return; } Transition pastedTransition = itemsToPaste.First() as Transition; Fx.Assert(pastedTransition != null, "Copied Transition should not be null."); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit(System.Activities.Presentation.SR.PropertyChangeEditingScopeDescription)) { string displayName = pastedTransition.DisplayName; bool isFirst = true; foreach (ModelItem selectedItem in selectedItems) { if (!isFirst) { StringReader reader = new StringReader(XamlServices.Save(pastedTransition)); pastedTransition = (Transition)XamlServices.Load(reader); } ModelItem transitionModelItem = this.Context.Services.GetRequiredService <ModelTreeManager>().WrapAsModelItem(pastedTransition); ModelItem sourceState = selectedItem; sourceState.Properties[StateDesigner.TransitionsPropertyName].Collection.Add(transitionModelItem); transitionModelItem.Properties[TransitionDesigner.ToPropertyName].SetValue(destinationState); if (isFirst) { this.ViewStateService.RemoveViewState(transitionModelItem, ConnectorLocationViewStateKey); this.ViewStateService.RemoveViewState(transitionModelItem, SrcConnectionPointIndexStateKey); this.ViewStateService.RemoveViewState(transitionModelItem, DestConnectionPointIndexStateKey); isFirst = false; } } es.Complete(); } } else { List <ModelItem> modelItemsPasted = new List <ModelItem>(); List <State> states = new List <State>(); foreach (object obj in itemsToPaste) { State state; if (obj is FinalState) { state = new State() { DisplayName = DefaultFinalStateDisplayName, IsFinal = true }; } else { state = (State)obj; if (state.DisplayName == null) { state.DisplayName = DefaultStateDisplayName; } } states.Add(state); } RemoveDanglingTransitions(states); using (EditingScope es = (EditingScope)this.ModelItem.BeginEdit( System.Activities.Presentation.SR.CollectionAddEditingScopeDescription)) { // Fix 157591 by storing the height and width of the container "before" the new states are added to the // panel, and group the insertion inside one editing scope - such that Undo will also restore the // size of the StateMachineContainer to pre-insert size. StoreShapeSizeWithUndoRecursively(this.ModelItem); foreach (State state in states) { ModelItem stateModelItem = (this.ModelItem.ItemType == typeof(StateMachine)) ? this.ModelItem.Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state) : GetStateMachineModelItem(this.ModelItem).Properties[StateMachineDesigner.StatesPropertyName].Collection.Add(state); modelItemsPasted.Add(stateModelItem); } es.Complete(); } if (modelItemsPasted.Count > 0) { // translate location view states to be in the coordinate system of the pasting target Fx.Assert(this.ModelItem.ItemType == typeof(StateMachine), "Only StateMachine contain the StateContainerEditor."); this.UpdateLocationViewStatesByMetaData(modelItemsPasted, metaData, this); if (pastePoint.X > 0 && pastePoint.Y > 0) { if (pastePointReference != null) { pastePoint = pastePointReference.TranslatePoint(pastePoint, this.panel); pastePoint.X = pastePoint.X < 0 ? 0 : pastePoint.X; pastePoint.Y = pastePoint.Y < 0 ? 0 : pastePoint.Y; } this.UpdateLocationViewStatesByPoint(modelItemsPasted, pastePoint); } // If paste point is not available, paste the items to the top left corner. else { this.UpdateLocationViewStatesToAvoidOverlap(modelItemsPasted); } } this.Dispatcher.BeginInvoke(() => { if (modelItemsPasted.Count > 0 && modelItemsPasted[0] != null) { Keyboard.Focus(modelItemsPasted[0].View as IInputElement); } this.Context.Items.SetValue(new Selection(modelItemsPasted)); }, DispatcherPriority.ApplicationIdle ); } }