public static void CopyBehaviorNodes(SceneViewModel viewModel, IList <BehaviorBaseNode> behaviorNodes) { PastePackage pastePackage = new PastePackage(viewModel); using (viewModel.ForceBaseValue()) { foreach (SceneNode childPropertyNode in (IEnumerable <BehaviorBaseNode>)behaviorNodes) { if (ProjectNeutralTypes.Behavior.IsAssignableFrom((ITypeId)childPropertyNode.Type)) { pastePackage.AddChildPropertyNode(childPropertyNode); } else { BehaviorTriggerActionNode triggerActionNode1 = (BehaviorTriggerActionNode)childPropertyNode; BehaviorTriggerBaseNode behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)triggerActionNode1.Parent; if (behaviorTriggerBaseNode.Actions.Count > 1) { DocumentNode node1 = triggerActionNode1.DocumentNode.Clone(viewModel.Document.DocumentContext); BehaviorTriggerActionNode triggerActionNode2 = (BehaviorTriggerActionNode)viewModel.GetSceneNode(node1); DocumentNode node2 = behaviorTriggerBaseNode.DocumentNode.Clone(viewModel.Document.DocumentContext); behaviorTriggerBaseNode = (BehaviorTriggerBaseNode)viewModel.GetSceneNode(node2); behaviorTriggerBaseNode.Actions.Clear(); behaviorTriggerBaseNode.Actions.Add((SceneNode)triggerActionNode2); } pastePackage.AddChildPropertyNode((SceneNode)behaviorTriggerBaseNode); } } } pastePackage.SendToClipboard(); }
public static void CopyPropertyNodes(SceneViewModel viewModel, IList <SceneNode> nodes) { if (nodes.Count == 0) { return; } PastePackage pastePackage = new PastePackage(viewModel); using (viewModel.ForceBaseValue()) pastePackage.AddChildPropertyNodes(nodes); pastePackage.SendToClipboard(); }
private static SceneElement ChangeLayoutType(SceneElement sourceElement, ITypeId layoutType, ref SceneElement elementContainingChildren) { IDocumentRoot documentRoot = sourceElement.DocumentNode.DocumentRoot; IDocumentContext documentContext = documentRoot.DocumentContext; SceneViewModel viewModel = sourceElement.ViewModel; Size size = Size.Empty; BaseFrameworkElement frameworkElement = sourceElement as BaseFrameworkElement; if (frameworkElement != null) { size = frameworkElement.GetComputedTightBounds().Size; } using (viewModel.ForceBaseValue()) { SceneElement sceneElement = (SceneElement)viewModel.CreateSceneNode(layoutType); using (viewModel.DisableUpdateChildrenOnAddAndRemove()) { using (viewModel.DisableDrawIntoState()) { viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)sourceElement); Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)sourceElement); Dictionary <IPropertyId, List <SceneNode> > storedChildren = ChangeLayoutTypeCommand.StoreChildren(sourceElement); if (sourceElement.DocumentNode == documentRoot.RootNode) { documentRoot.RootNode = sceneElement.DocumentNode; sceneElement.DocumentNode.NameScope = new DocumentNodeNameScope(); } else { ISceneNodeCollection <SceneNode> collectionContainer = sourceElement.GetCollectionContainer(); int index = collectionContainer.IndexOf((SceneNode)sourceElement); sourceElement.Remove(); collectionContainer.Insert(index, (SceneNode)sceneElement); } SceneElementHelper.ApplyProperties((SceneNode)sceneElement, properties); elementContainingChildren = ChangeLayoutTypeCommand.ApplyChildren(sceneElement, storedChildren, size); } } if (sceneElement is GridElement || sceneElement is CanvasElement) { ILayoutDesigner designerForChild = sceneElement.ViewModel.GetLayoutDesignerForChild(sceneElement, true); if ((designerForChild.GetWidthConstraintMode((BaseFrameworkElement)sceneElement) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { sceneElement.SetValue(BaseFrameworkElement.WidthProperty, (object)size.Width); } if ((designerForChild.GetHeightConstraintMode((BaseFrameworkElement)sceneElement) & LayoutConstraintMode.CanvasLike) != LayoutConstraintMode.NonOverlappingGridlike) { sceneElement.SetValue(BaseFrameworkElement.HeightProperty, (object)size.Height); } } return(sceneElement); } }
public static void CopyElements(SceneViewModel viewModel, List <SceneElement> elements) { if (elements.Count == 0 || !CopyCommand.ElementsHaveSameParent((ICollection <SceneElement>)elements)) { return; } PerformanceUtility.StartPerformanceSequence(PerformanceEvent.CopyElements); SceneNode parent = elements[0].Parent; PastePackage pastePackage = new PastePackage(viewModel); using (viewModel.ForceBaseValue()) pastePackage.AddElements(elements, true); pastePackage.SendToClipboard(); PerformanceUtility.EndPerformanceSequence(PerformanceEvent.CopyElements); }
public static PathElement ConvertToPath(BaseFrameworkElement element) { SceneViewModel viewModel = element.ViewModel; PathGeometry pathGeometry = PathConversionHelper.ConvertToPathGeometry((SceneElement)element); PathElement pathElement = (PathElement)viewModel.CreateSceneNode(PlatformTypes.Path); ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)element, true); Rect childRect = designerForChild.GetChildRect(element); Transform transform1 = Transform.Identity; if (element.IsSet(Base2DElement.RenderTransformProperty) == PropertyState.Set) { transform1 = (Transform)element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty); } Point point1 = new Point(0.5, 0.5); if (element.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Set) { point1 = (Point)element.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty); } bool flag = false; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitConvertToPath, true)) { using (viewModel.ForceBaseValue()) { pathElement.PathGeometry = pathGeometry; pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill); Brush textForeground = PathCommandHelper.GetTextForeground(element); if (textForeground != null) { flag = true; pathElement.SetValueAsWpf(ShapeElement.FillProperty, (object)textForeground); } viewModel.AnimationEditor.DeleteAllAnimations((SceneNode)element); Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)element); ISceneNodeCollection <SceneNode> collectionForChild = element.Parent.GetCollectionForChild((SceneNode)element); int index = collectionForChild.IndexOf((SceneNode)element); collectionForChild[index] = (SceneNode)pathElement; if (flag) { List <IPropertyId> list = new List <IPropertyId>(); foreach (KeyValuePair <IPropertyId, SceneNode> keyValuePair in properties) { IPropertyId key = keyValuePair.Key; DependencyPropertyReferenceStep propertyReferenceStep = key as DependencyPropertyReferenceStep; if (propertyReferenceStep != null && !propertyReferenceStep.IsAttachable && (propertyReferenceStep.MemberType != MemberType.DesignTimeProperty && !PlatformTypeHelper.GetDeclaringType((IMember)propertyReferenceStep).IsAssignableFrom(typeof(Path)))) { list.Add(key); } } foreach (IPropertyId key in list) { properties.Remove(key); } } SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties); } if (ProjectNeutralTypes.PrimitiveShape.IsAssignableFrom((ITypeId)element.Type)) { using (viewModel.ForceBaseValue()) { Rect bounds = pathGeometry.Bounds; double halfStrokeWidth = PathCommandHelper.GetHalfStrokeWidth(pathElement); bounds.Inflate(halfStrokeWidth / 2.0, halfStrokeWidth / 2.0); if (transform1 != Transform.Identity && bounds.Size != childRect.Size) { Point point2 = (Point)pathElement.GetComputedValueAsWpf(Base2DElement.RenderTransformOriginProperty); Point point3 = new Point(point2.X * childRect.Width, point2.Y * childRect.Height); Point point4 = new Point((point3.X - bounds.X) / bounds.Width, (point3.Y - bounds.Y) / bounds.Height); pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point4); } bounds.Offset(childRect.Left, childRect.Top); editTransaction.Update(); designerForChild.SetChildRect((BaseFrameworkElement)pathElement, bounds); } } if (flag && !pathGeometry.IsEmpty()) { using (viewModel.ForceBaseValue()) { Rect bounds = pathGeometry.Bounds; bounds.Offset(childRect.Left, childRect.Top); Point point2 = new Point(bounds.Left + point1.X * bounds.Width, bounds.Top + point1.Y * bounds.Height); Point point3 = new Point(childRect.Left + childRect.Width * point1.X, childRect.Top + childRect.Height * point1.Y); Point point4 = new TransformGroup() { Children = { (Transform) new TranslateTransform(-point3.X, -point3.Y), transform1, (Transform) new TranslateTransform(point3.X, point3.Y) } }.Transform(point2); Transform transform2 = (Transform) new CanonicalTransform(transform1) { TranslationX = 0.0, TranslationY = 0.0 }.TransformGroup; Rect rect = new Rect(point4.X - bounds.Width * point1.X, point4.Y - bounds.Height * point1.Y, bounds.Width, bounds.Height); pathElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)point1); editTransaction.Update(); designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect); pathElement.RenderTransform = transform2; } } editTransaction.Commit(); } return(pathElement); }
public virtual bool AddToDocument(IProjectItem projectItem, IView view, ISceneInsertionPoint insertionPoint, Rect rect) { SceneView sceneView = view as SceneView; if (sceneView != null && sceneView.IsDesignSurfaceEnabled && insertionPoint != null) { SceneViewModel viewModel = sceneView.ViewModel; string str = insertionPoint.SceneNode.DocumentNode.Context.MakeResourceReference(projectItem.DocumentReference.Path); if (!string.IsNullOrEmpty(str)) { SceneElement element = this.CreateElement(viewModel, insertionPoint, str); if (element != null) { try { using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.AssetAddAssetUndo)) { IList <SceneElement> list = this.AddToDocumentInternal(str, element, insertionPoint, viewModel, editTransaction); editTransaction.Update(); if (sceneView.IsValid && list.Count > 0) { element = list[0]; if (element != null && element.IsViewObjectValid && (this.designerContext.ActiveView == sceneView && sceneView.ViewRoot != null) && element.Visual != null) { sceneView.EnsureVisible(element.Visual); } BaseFrameworkElement child = element as BaseFrameworkElement; if (child != null) { SetRectMode setRectMode = SetRectMode.CreateAtPosition; if (rect.IsEmpty) { rect = new Rect(0.0, 0.0, double.PositiveInfinity, double.PositiveInfinity); setRectMode = SetRectMode.CreateDefault; } if (double.IsPositiveInfinity(rect.Width)) { rect.Width = this.GetNativeWidth((SceneElement)child); } if (double.IsPositiveInfinity(rect.Height)) { rect.Height = this.GetNativeHeight((SceneElement)child); } using (viewModel.ForceBaseValue()) { ILayoutDesigner designerForChild = viewModel.GetLayoutDesignerForChild((SceneElement)child, true); LayoutOverrides layoutOverrides = LayoutOverrides.HorizontalAlignment | LayoutOverrides.VerticalAlignment; designerForChild.SetChildRect(child, rect, LayoutOverrides.None, layoutOverrides, layoutOverrides, setRectMode); } } viewModel.ElementSelectionSet.SetSelection((ICollection <SceneElement>)list, (SceneElement)null); } editTransaction.Commit(); } return(true); } catch (InvalidOperationException ex) { this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.AssetElementInsertionFailedDialogMessage, new object[2] { (object)element.Name, (object)ex.Message })); } } } } return(false); }
private static SceneElement PasteElement(SceneViewModel viewModel, SceneElement element, List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater, ISceneInsertionPoint insertionPoint) { SceneNodeIDHelper sceneNodeIdHelper = new SceneNodeIDHelper(viewModel, (SceneNode)insertionPoint.SceneNode.StoryboardContainer); SceneElement element1 = (SceneElement)null; using (viewModel.ForceBaseValue()) { PasteCommand.StripStoryboardsAndTriggers(element); PasteCommand.StripExtraNamespaces(element); BaseFrameworkElement frameworkElement = element as BaseFrameworkElement; if (frameworkElement != null || element is DataGridColumnNode) { if (!(insertionPoint.SceneElement is Viewport3DElement) && !(insertionPoint.SceneElement is Base3DElement)) { if (insertionPoint.CanInsert((ITypeId)element.Type)) { if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)insertionPoint.SceneElement.Type) && (!PlatformTypes.UserControl.Equals((object)insertionPoint.SceneElement.Type) || insertionPoint.SceneElement.DocumentNode.DocumentRoot.RootNode != insertionPoint.SceneElement.DocumentNode)) { if (element.Name != null) { string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)element, element.Name); sceneNodeIdHelper.SetLocalName((SceneNode)element, validCopiedElementId); } sceneNodeIdHelper.FixNameConflicts((SceneNode)element); } if (viewModel.DesignerContext.PrototypingService != null) { viewModel.DesignerContext.PrototypingService.ProcessElementBeforeInsertion(insertionPoint, element); } insertionPoint.Insert((SceneNode)element); if (element.GetLocalValue(DesignTimeProperties.LayoutRectProperty) != null && frameworkElement != null) { elementsToTranslateLater.Add(new PasteCommand.DelayedElementTranslationInfo(frameworkElement)); } element1 = element; } } else if (element.TargetType == typeof(Image)) { GeometryModel3DElement geometryModel3Delement = GeometryCreationHelper3D.ConvertImageTo3D(viewModel, frameworkElement, element.Name); IChildContainer3D childContainer3D = insertionPoint.SceneElement as IChildContainer3D; if (childContainer3D != null) { childContainer3D.AddChild(viewModel, (Base3DElement)geometryModel3Delement); element1 = (SceneElement)geometryModel3Delement; } } } else { Base3DElement child; if ((child = element as Base3DElement) != null) { if (child.Name != null) { string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)child, child.Name); sceneNodeIdHelper.SetLocalName((SceneNode)child, validCopiedElementId); } DependencyPropertyReferenceStep propertyReferenceStep = insertionPoint.Property as DependencyPropertyReferenceStep; if (propertyReferenceStep != null && propertyReferenceStep.DependencyProperty == ModelVisual3D.ContentProperty) { Model3DElement model3Delement = BaseElement3DCoercionHelper.CoerceToModel3D(viewModel, (SceneElement)child); if (model3Delement != null) { insertionPoint.Insert((SceneNode)model3Delement); element1 = (SceneElement)model3Delement; } } else { IChildContainer3D childContainer3D = insertionPoint.SceneElement as IChildContainer3D; if (childContainer3D != null) { element1 = childContainer3D.AddChild(viewModel, child); } } } } if (element1 != null) { if (!(viewModel.ActiveEditingContainer is FrameworkTemplateElement)) { PasteCommand.StripTemplateBindings(element1); } } } return(element1); }
private static ICollection <SceneNode> PasteData(SceneViewModel viewModel, SafeDataObject dataObject, ISceneInsertionPoint insertionPoint, bool allowInsertionPointChange, out bool canceledPasteOperation) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.PasteElements); canceledPasteOperation = false; List <SceneNode> list = new List <SceneNode>(); PastePackage pastePackage = PastePackage.FromData(viewModel, dataObject); if (pastePackage != null) { if (allowInsertionPointChange) { insertionPoint = PasteCommand.ComputeNewInsertionPoint(viewModel, insertionPoint, pastePackage); } if (!PasteCommand.CanAddMultipleElements(insertionPoint.SceneElement, pastePackage.Elements.Count)) { string name = insertionPoint.SceneElement.TargetType.Name; viewModel.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PasteMultipleInSingleContainerError, new object[1] { (object)name })); } else if (pastePackage.Elements.Count == 0 && pastePackage.Storyboards.Count == 0 && pastePackage.Resources.Count > 0) { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedNoElementsDialogMessage); } else { IDictionary <DocumentNode, string> imageMap = (IDictionary <DocumentNode, string>) new Dictionary <DocumentNode, string>(); foreach (SceneNode sceneNode in pastePackage.Elements) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } foreach (SceneNode sceneNode in pastePackage.Resources) { foreach (KeyValuePair <DocumentNode, string> keyValuePair in (IEnumerable <KeyValuePair <DocumentNode, string> >)Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CreateImageReferenceMap(sceneNode.DocumentNode, pastePackage, viewModel)) { imageMap.Add(keyValuePair); } } int index = 0; ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(viewModel.RootNode.DocumentNode); if (resourcesCollection != null && resourcesCollection.Resources != null && resourcesCollection.Resources.SupportsChildren) { index = resourcesCollection.Resources.Children.Count; } if (Microsoft.Expression.DesignSurface.Utility.ResourceHelper.PasteResources(pastePackage, imageMap, ResourceConflictResolution.UseExisting | ResourceConflictResolution.RenameNew | ResourceConflictResolution.OverwriteOld, viewModel.RootNode, index, false)) { ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(insertionPoint.SceneElement, true); List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater = new List <PasteCommand.DelayedElementTranslationInfo>(pastePackage.Elements.Count); string copyElementToken = pastePackage.ClipboardCopyElementToken; foreach (SceneElement element in pastePackage.Elements) { SceneElement sceneElement = PasteCommand.PasteElement(viewModel, element, elementsToTranslateLater, insertionPoint); if (sceneElement != null) { Microsoft.Expression.DesignSurface.Utility.ResourceHelper.UpdateImageReferences(sceneElement.DocumentNode, imageMap, pastePackage, viewModel); list.Add((SceneNode)sceneElement); sceneElement.ClearValue(DesignTimeProperties.CopyTokenProperty); } } if (copyElementToken != null) { pastePackage.SetGlobalCopyElementToken(copyElementToken); PastePackage.PasteSelectionChangePending = true; } foreach (SceneNode childProperty in pastePackage.ChildPropertyNodes) { PasteCommand.PasteChildProperty(viewModel, childProperty, (IList <SceneNode>)list); } foreach (StoryboardTimelineSceneNode storyboard in pastePackage.Storyboards) { PasteCommand.PasteStoryboard(viewModel, storyboard, (IList <SceneNode>)list); } viewModel.Document.OnUpdatedEditTransaction(); viewModel.DefaultView.UpdateLayout(); using (viewModel.ForceBaseValue()) { Rect empty = Rect.Empty; foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater) { empty.Union(elementTranslationInfo.Bounds); } foreach (PasteCommand.DelayedElementTranslationInfo elementTranslationInfo in elementsToTranslateLater) { elementTranslationInfo.UpdateTranslation(designerForParent, empty); } } } else { canceledPasteOperation = true; } } } else if (dataObject.GetDataPresent(DataFormats.FileDrop)) { DesignerContext designerContext = viewModel.DesignerContext; string[] supportedFiles = FileDropToolBehavior.CreateImageOrMediaDrop(designerContext).GetSupportedFiles(ClipboardService.GetDataObject()); if (supportedFiles.Length > 0) { IEnumerable <IProjectItem> importedItems = designerContext.ActiveProject.AddItems(Enumerable.Select <string, DocumentCreationInfo>((IEnumerable <string>)supportedFiles, (Func <string, DocumentCreationInfo>)(file => new DocumentCreationInfo() { SourcePath = file }))); FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, importedItems, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint); } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else if (dataObject.GetDataPresent(DataFormats.Bitmap)) { DesignerContext designerContext = viewModel.DesignerContext; IProjectItem projectItem = CutBuffer.AddImageDataFromClipboard(designerContext.ProjectManager, designerContext.ActiveProject); if (projectItem != null) { FileDropToolBehavior.AddItemsToDocument(viewModel.DefaultView, (IEnumerable <IProjectItem>) new List <IProjectItem>() { projectItem }, new Point(0.0, 0.0), viewModel.ActiveSceneInsertionPoint); } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } } else { viewModel.DesignerContext.MessageDisplayService.ShowError(StringTable.PasteElementsFailedDialogMessage); } return((ICollection <SceneNode>)list); }
public override void Execute() { string fileName = "test"; IProject activeProject = this.DesignerContext.ActiveProject; TemplateItemHelper templateItemHelper = new TemplateItemHelper(activeProject, (IList <string>)null, (IServiceProvider)this.DesignerContext.Services); IProjectItemTemplate templateItem = templateItemHelper.FindTemplateItem("UserControl"); if (templateItem == null) { this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlTemplateNotFound); } else { SceneViewModel activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel; List <SceneElement> elements = new List <SceneElement>(); elements.AddRange((IEnumerable <SceneElement>)activeSceneViewModel.ElementSelectionSet.Selection); elements.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(activeSceneViewModel.RootNode)); if (this.ShowUI) { string recommendedName = this.GetRecommendedName((IEnumerable <SceneElement>)elements); MakeUserControlDialog userControlDialog = new MakeUserControlDialog(this.DesignerContext, this.DialogTitle, templateItemHelper, recommendedName); bool?nullable = userControlDialog.ShowDialog(); if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0) { return; } fileName = userControlDialog.ControlName; } List <IProjectItem> itemsToOpen = (List <IProjectItem>)null; IProjectItem projectItem1 = (IProjectItem)null; IEnumerable <IProjectItem> source = (IEnumerable <IProjectItem>)null; try { source = templateItemHelper.AddProjectItemsForTemplateItem(templateItem, fileName, this.DesignerContext.ProjectManager.TargetFolderForProject(activeProject), CreationOptions.DoNotAllowOverwrites | CreationOptions.DoNotSelectCreatedItems | CreationOptions.DoNotSetDefaultImportPath, out itemsToOpen); } catch (Exception ex) { if (ex is NotSupportedException || ErrorHandling.ShouldHandleExceptions(ex)) { this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.ProjectNewFileErrorDialogMessage, new object[2] { (object)fileName, (object)ex.Message })); } else { throw; } } if (source == null || EnumerableExtensions.CountIsLessThan <IProjectItem>(source, 1)) { return; } if (itemsToOpen != null && itemsToOpen.Count > 0) { projectItem1 = Enumerable.FirstOrDefault <IProjectItem>((IEnumerable <IProjectItem>)itemsToOpen); projectItem1.OpenDocument(false, true); } if (projectItem1 != null && projectItem1.IsOpen && projectItem1.DocumentType.CanView) { Rect empty = Rect.Empty; for (int index = 0; index < elements.Count; ++index) { BaseFrameworkElement child = elements[index] as BaseFrameworkElement; if (child != null) { Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child); empty.Union(childRect); } } Rect rect = RoundingHelper.RoundRect(empty); SceneElement parentElement = elements[0].ParentElement; bool useLayoutRounding = LayoutRoundingHelper.GetUseLayoutRounding(parentElement); DataObject dataObject = (DataObject)null; using (activeSceneViewModel.ForceBaseValue()) { PastePackage pastePackage = new PastePackage(activeSceneViewModel); pastePackage.CopyStoryboardsReferencingElements = true; pastePackage.AddElements(elements); dataObject = pastePackage.GetPasteDataObject(); } SceneView sceneView = projectItem1.OpenView(true) as SceneView; if (sceneView != null) { SceneViewModel viewModel = sceneView.ViewModel; ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(viewModel.ViewRoot.ProjectContext); ClassAttributes rootClassAttributes = viewModel.DocumentRoot.RootClassAttributes; ITypeId typeId = (ITypeId)null; if (projectXamlContext != null && rootClassAttributes != null) { projectXamlContext.RefreshUnbuiltTypeDescriptions(); if (rootClassAttributes != null) { typeId = (ITypeId)projectXamlContext.GetType(projectXamlContext.ProjectAssembly.Name, rootClassAttributes.QualifiedClassName); } } if (typeId != null && this.CheckForCircularReference((IEnumerable <SceneElement>)elements, typeId)) { this.DesignerContext.MessageDisplayService.ShowError(StringTable.MakeUserControlCircularReferenceFound); this.CleanupAfterCancel(projectItem1); return; } using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl)) { if (!rect.IsEmpty) { viewModel.RootNode.SetValue(DesignTimeProperties.DesignWidthProperty, (object)rect.Width); viewModel.RootNode.SetValue(DesignTimeProperties.DesignHeightProperty, (object)rect.Height); if (this.AddToApplicationFlow) { viewModel.RootNode.SetValue(BaseFrameworkElement.WidthProperty, (object)rect.Width); viewModel.RootNode.SetValue(BaseFrameworkElement.HeightProperty, (object)rect.Height); } } IProperty property = LayoutRoundingHelper.ResolveUseLayoutRoundingProperty(viewModel.RootNode); if (property != null) { viewModel.RootNode.SetValue((IPropertyId)property, (object)(bool)(useLayoutRounding ? true : false)); } ILayoutDesigner designerForParent = viewModel.GetLayoutDesignerForParent(viewModel.ActiveSceneInsertionPoint.SceneElement, true); bool canceledPasteOperation; ICollection <SceneNode> nodes = PasteCommand.PasteData(viewModel, new SafeDataObject((IDataObject)dataObject), viewModel.ActiveSceneInsertionPoint, out canceledPasteOperation); if (canceledPasteOperation) { editTransaction.Cancel(); this.CleanupAfterCancel(projectItem1); return; } editTransaction.Update(); if (nodes.Count > 0) { viewModel.DefaultView.UpdateLayout(); viewModel.SelectNodes(nodes); if (designerForParent != null) { foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)nodes) { BaseFrameworkElement child = sceneNode as BaseFrameworkElement; if (child != null && child.IsViewObjectValid) { Rect childRect = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).GetChildRect(child); childRect.Location = (Point)(childRect.Location - rect.Location); designerForParent.SetChildRect(child, childRect); } } } } editTransaction.Commit(); } if (this.AddToApplicationFlow && this.DesignerContext.PrototypingService != null) { this.DesignerContext.PrototypingService.PromoteToCompositionScreen(projectItem1); } if (typeId != null) { using (activeSceneViewModel.ForceBaseValue()) { using (activeSceneViewModel.DisableDrawIntoState()) { using (SceneEditTransaction editTransaction = activeSceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeUserControl)) { using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { SceneElement primarySelection = activeSceneViewModel.ElementSelectionSet.PrimarySelection; IProperty propertyForChild = parentElement.GetPropertyForChild((SceneNode)primarySelection); PropertySceneInsertionPoint sceneInsertionPoint = new PropertySceneInsertionPoint(parentElement, propertyForChild); SceneNode sceneNode = (SceneNode)null; if (sceneInsertionPoint.CanInsert(typeId)) { foreach (SceneElement element in elements) { if (element != primarySelection) { activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element); element.Remove(); } } ISceneNodeCollection <SceneNode> collectionForProperty = parentElement.GetCollectionForProperty((IPropertyId)propertyForChild); int index = collectionForProperty.IndexOf((SceneNode)primarySelection); activeSceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection); primarySelection.Remove(); sceneNode = activeSceneViewModel.CreateSceneNode(typeId); collectionForProperty.Insert(index, sceneNode); this.DesignerContext.ViewService.ActiveView = (IView)activeSceneViewModel.DefaultView; editTransaction.Update(); activeSceneViewModel.DefaultView.UpdateLayout(); BaseFrameworkElement child = sceneNode as BaseFrameworkElement; if (child != null && child.IsViewObjectValid) { activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true).SetChildRect(child, rect); } } if (this.AddToApplicationFlow) { if (sceneNode != null) { sceneNode.SetValue(DesignTimeProperties.IsPrototypingCompositionProperty, (object)true); } } } editTransaction.Commit(); } } } this.DesignerContext.ViewService.ActiveView = (IView)viewModel.DefaultView; } } } if (itemsToOpen == null || itemsToOpen.Count <= 1) { return; } foreach (IProjectItem projectItem2 in itemsToOpen) { if (projectItem1 != projectItem2) { projectItem2.OpenView(true); } } } }