public override void Insert(ISceneNodeCollection <SceneNode> children, SceneElement element) { if (this.Index > children.Count) { this.Index = children.Count; } children.Insert(this.Index, (SceneNode)element); }
public override void Execute() { BaseFrameworkElement selectedElement = this.SelectedElement; SceneViewModel sceneViewModel1 = this.SceneViewModel; bool flag1 = true; BaseFrameworkElement frameworkElement = selectedElement; int num1 = flag1 ? true : false; ILayoutDesigner designerForChild = sceneViewModel1.GetLayoutDesignerForChild((SceneElement)frameworkElement, num1 != 0); SceneNode parent = selectedElement.Parent; IProperty propertyForChild = parent.GetPropertyForChild((SceneNode)selectedElement); ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild); int index = collectionForProperty.IndexOf((SceneNode)selectedElement); if (!BehaviorHelper.EnsureBlendSDKLibraryAssemblyReferenced(this.SceneViewModel, "Microsoft.Expression.Controls") || !ProjectContext.GetProjectContext(selectedElement.ProjectContext).IsTypeSupported(ProjectNeutralTypes.PathListBox)) { return; } using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { SceneViewModel sceneViewModel2 = this.SceneViewModel; bool flag2 = false; string unitMakeLayoutPath = StringTable.UndoUnitMakeLayoutPath; int num2 = flag2 ? true : false; using (SceneEditTransaction editTransaction = sceneViewModel2.CreateEditTransaction(unitMakeLayoutPath, num2 != 0)) { using (this.SceneViewModel.ForceBaseValue()) { using (this.SceneViewModel.DisableDrawIntoState()) { this.SceneViewModel.ElementSelectionSet.Clear(); Rect childRect = designerForChild.GetChildRect(selectedElement); selectedElement.EnsureNamed(); PathListBoxElement pathListBoxElement = (PathListBoxElement)this.SceneViewModel.CreateSceneNode(ProjectNeutralTypes.PathListBox); LayoutPathNode layoutPathNode = (LayoutPathNode)this.SceneViewModel.CreateSceneNode(ProjectNeutralTypes.LayoutPath); BindingSceneNode bindingSceneNode = (BindingSceneNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Binding); bindingSceneNode.ElementName = selectedElement.Name; layoutPathNode.SetValue(LayoutPathNode.SourceElementProperty, (object)bindingSceneNode.DocumentNode); pathListBoxElement.LayoutPaths.Add((SceneNode)layoutPathNode); if (!collectionForProperty.FixedCapacity.HasValue || collectionForProperty.Count < collectionForProperty.FixedCapacity.Value) { collectionForProperty.Insert(index, (SceneNode)pathListBoxElement); } else { GridElement gridElement = (GridElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid); collectionForProperty[index] = (SceneNode)gridElement; gridElement.Children.Add((SceneNode)pathListBoxElement); gridElement.Children.Add((SceneNode)selectedElement); } editTransaction.Update(); designerForChild.SetChildRect((BaseFrameworkElement)pathListBoxElement, childRect); this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)pathListBoxElement); editTransaction.Commit(); } } } } }
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 override void Execute() { PerformanceUtility.StartPerformanceSequence(PerformanceEvent.Make3D); try { using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { BaseFrameworkElement frameworkElement = (BaseFrameworkElement)this.SceneViewModel.ElementSelectionSet.PrimarySelection; using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.UndoUnitName, false)) { ILayoutDesigner designerForChild = this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true); Rect childRect = designerForChild.GetChildRect(frameworkElement); DocumentNode newValue = this.CreateValue(frameworkElement); if (newValue == null) { editTransaction.Cancel(); } else if (this.CreateResource && this.ProcessAsResource(frameworkElement, newValue) == null) { editTransaction.Cancel(); } else { if (this.ShouldReplaceOriginal) { this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)frameworkElement); Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)frameworkElement, true); this.SceneViewModel.ElementSelectionSet.Clear(); BaseFrameworkElement element = this.CreateElement(frameworkElement); using (this.SceneViewModel.ForceBaseValue()) { element.Name = frameworkElement.Name; ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement); int index = collectionForChild.IndexOf((SceneNode)frameworkElement); frameworkElement.Remove(); this.Postprocess(frameworkElement, element, properties, childRect); collectionForChild.Insert(index, (SceneNode)element); SceneElementHelper.ApplyProperties((SceneNode)element, properties); editTransaction.Update(); designerForChild.SetChildRect(element, childRect); } this.SceneViewModel.ElementSelectionSet.SetSelection((SceneElement)element); } editTransaction.Commit(); } } } } finally { PerformanceUtility.EndPerformanceSequence(PerformanceEvent.Make3D); } }
protected override void ReorderElements(ISceneNodeCollection <SceneNode> childCollection, SceneElementCollection selectedChildren) { if (childCollection.Count == selectedChildren.Count) { return; } for (int index = selectedChildren.Count - 1; index >= 0; --index) { SceneElement sceneElement = selectedChildren[index]; sceneElement.Remove(); childCollection.Insert(0, (SceneNode)sceneElement); } }
public static List <PathElement> ReleaseCompoundPaths(PathElement pathElement, SceneEditTransaction editTransaction) { List <PathElement> list = new List <PathElement>(); PathGeometry pathGeometry1 = pathElement.PathGeometry; Transform geometryTransform = pathElement.GeometryTransform; ISceneNodeCollection <SceneNode> collectionContainer = pathElement.GetCollectionContainer(); int num = collectionContainer.IndexOf((SceneNode)pathElement); int oldFigureIndex = 0; foreach (PathFigure original in pathGeometry1.Figures) { PathFigure pathFigure = PathFigureUtilities.Copy(original, geometryTransform); PathGeometry pathGeometry2 = new PathGeometry(); if (pathGeometry1.Transform != null && pathGeometry1.Transform.Value != Matrix.Identity) { pathGeometry2.Transform = pathGeometry1.Transform.Clone(); } if (pathGeometry2.FillRule != pathGeometry1.FillRule) { pathGeometry2.FillRule = pathGeometry1.FillRule; } pathGeometry2.Figures.Add(pathFigure); DocumentNode node = pathElement.DocumentNode.Clone(pathElement.DocumentContext); PathElement pathElement1 = (PathElement)pathElement.ViewModel.GetSceneNode(node); collectionContainer.Insert(num++, (SceneNode)pathElement1); Rect extent = pathGeometry2.Bounds; extent = PathCommandHelper.InflateRectByStrokeWidth(extent, pathElement1, false); Vector vector = new Vector(-extent.Left, -extent.Top); PathCommandHelper.ReplacePathGeometry(pathElement1, pathGeometry2, editTransaction); Matrix transformToElement = pathElement.GetComputedTransformToElement((SceneElement)pathElement1); transformToElement.OffsetX += vector.X; transformToElement.OffsetY += vector.Y; PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform); PathCommandHelper.TransferPathFigureAnimations(pathElement, pathElement1, propertyReference, oldFigureIndex, 0, (Transform) new MatrixTransform(transformToElement)); PathCommandHelper.AdjustPathForAnimations(pathElement1, editTransaction); list.Add(pathElement1); ++oldFigureIndex; } string name = pathElement.Name; pathElement.ViewModel.ElementSelectionSet.RemoveSelection((SceneElement)pathElement); pathElement.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)pathElement); pathElement.Remove(); foreach (SceneNode sceneNode in list) { sceneNode.Name = name; } return(list); }
protected override void ReorderElements(ISceneNodeCollection <SceneNode> childCollection, SceneElementCollection selectedChildren) { if (childCollection.Count == selectedChildren.Count) { return; } for (int index = 0; index < selectedChildren.Count; ++index) { SceneElement sceneElement = selectedChildren[index]; int num = childCollection.IndexOf((SceneNode)sceneElement); if (num > 0 && !selectedChildren.Contains(childCollection[num - 1] as SceneElement)) { sceneElement.Remove(); childCollection.Insert(num - 1, (SceneNode)sceneElement); } } }
protected override void ReorderElements(ISceneNodeCollection <SceneNode> childCollection, SceneElementCollection selectedChildren) { if (childCollection.Count == selectedChildren.Count) { return; } int num1 = childCollection.Count - 1; for (int index = selectedChildren.Count - 1; index >= 0; --index) { SceneElement sceneElement = selectedChildren[index]; int num2 = childCollection.IndexOf((SceneNode)sceneElement); if (num2 < num1 && !selectedChildren.Contains(childCollection[num2 + 1] as SceneElement)) { sceneElement.Remove(); childCollection.Insert(num2 + 1, (SceneNode)sceneElement); } } }
public override void Execute() { using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeCompoundPath)) { SceneElementSelectionSet elementSelectionSet = this.SceneViewModel.ElementSelectionSet; List <PathElement> otherElements = new List <PathElement>(); foreach (SceneElement element in elementSelectionSet.Selection) { PathElement pathElement = element as PathElement; if (pathElement != null) { otherElements.Add(pathElement); } else if (PathConversionHelper.CanConvert(element)) { otherElements.Add(PathCommandHelper.ConvertToPath((BaseFrameworkElement)element)); } } editTransaction.Update(); this.DesignerContext.ActiveView.UpdateLayout(); otherElements.Sort((IComparer <PathElement>) new ZOrderComparer <PathElement>(this.SceneViewModel.RootNode)); elementSelectionSet.Clear(); PathElement mainElement = otherElements[0]; BaseFrameworkElement frameworkElement = (BaseFrameworkElement)otherElements[otherElements.Count - 1]; ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement); int num = collectionForChild.IndexOf((SceneNode)frameworkElement); SceneNode sceneNode = num + 1 < collectionForChild.Count ? collectionForChild[num + 1] : (SceneNode)null; otherElements.RemoveAt(0); PathCommandHelper.MakeCompoundPath(mainElement, otherElements, editTransaction); mainElement.Remove(); if (sceneNode == null) { collectionForChild.Add((SceneNode)mainElement); } else { collectionForChild.Insert(collectionForChild.IndexOf(sceneNode), (SceneNode)mainElement); } elementSelectionSet.SetSelection((SceneElement)mainElement); editTransaction.Commit(); } }
internal static void ReparentAction(ISceneNodeCollection <SceneNode> triggersCollection, BehaviorTriggerBaseNode oldTrigger, BehaviorTriggerBaseNode newTrigger, BehaviorTriggerActionNode action) { SceneViewModel viewModel = oldTrigger.ViewModel; viewModel.BehaviorSelectionSet.Clear(); int num = triggersCollection.IndexOf((SceneNode)oldTrigger); DocumentNodeHelper.PreserveFormatting(action.DocumentNode); oldTrigger.Actions.Remove((SceneNode)action); viewModel.Document.OnUpdatedEditTransaction(); if (oldTrigger.Actions.Count == 0) { triggersCollection.RemoveAt(num--); } if (!triggersCollection.Contains((SceneNode)newTrigger)) { triggersCollection.Insert(num + 1, (SceneNode)newTrigger); } newTrigger.Actions.Add((SceneNode)action); viewModel.BehaviorSelectionSet.SetSelection((BehaviorBaseNode)action); }
public void Insert(SceneNode nodeToInsert) { if (this.ShouldNestContents(nodeToInsert)) { this.NestContents(nodeToInsert); } else { ISceneNodeCollection <SceneNode> destinationCollection = this.DestinationCollection; if (destinationCollection.FixedCapacity.HasValue && destinationCollection.Count >= destinationCollection.FixedCapacity.Value) { PropertySceneInsertionPoint.Cleanup(destinationCollection[destinationCollection.Count - 1]); } if (this.index >= 0 && this.index < destinationCollection.Count) { destinationCollection.Insert(this.index, nodeToInsert); } else { destinationCollection.Add(nodeToInsert); } } }
public override void Execute(object arg) { DesignerContext designerContext = this.DesignerContext; SceneViewModel activeSceneViewModel = designerContext.ActiveSceneViewModel; ITypeId type = this.Type; if (type is ProjectNeutralTypeId) { bool flag = activeSceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.DesignerContext.ActiveSceneViewModel.ProjectContext, type); if (!flag && this.IsDragDropContainer) { IMessageDisplayService messageDisplayService = activeSceneViewModel.DesignerContext.MessageDisplayService; flag = ToolkitHelper.EnsureSilverlightToolkitTypeAvailable((ITypeResolver)activeSceneViewModel.ProjectContext, type, messageDisplayService, StringTable.SilverlightToolkitDragDropNotInstalled, StringTable.SilverlightToolkitDragDropIncorrectVersion); } if (!flag) { return; } } using (SceneEditTransaction editTransaction = designerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitGroupIntoLayoutType, new object[1] { (object)this.Type.Name }))) { List <SceneElement> list1 = new List <SceneElement>(); List <SceneNode> elements = new List <SceneNode>(); list1.AddRange((IEnumerable <SceneElement>)designerContext.SelectionManager.ElementSelectionSet.Selection); GroupIntoLayoutTypeCommand.OrientationHelper orientationHelper = new GroupIntoLayoutTypeCommand.OrientationHelper(); list1.Sort((IComparer <SceneElement>) new ZOrderComparer <SceneElement>(this.SceneViewModel.RootNode)); List <LayoutCacheRecord> list2 = new List <LayoutCacheRecord>(list1.Count); Rect empty = Rect.Empty; for (int index = 0; index < list1.Count; ++index) { list2.Add((LayoutCacheRecord)null); BaseFrameworkElement element = list1[index] as BaseFrameworkElement; if (element != null) { ILayoutDesigner designerForChild = element.ViewModel.GetLayoutDesignerForChild((SceneElement)element, true); Rect roundedUpChildRect = LayoutRoundingHelper.GetRoundedUpChildRect(designerForChild, element); empty.Union(roundedUpChildRect); orientationHelper.AddChildRect((SceneNode)element, roundedUpChildRect); LayoutCacheRecord layoutCacheRecord = designerForChild.CacheLayout(element); list2[index] = layoutCacheRecord; elements.Add((SceneNode)element); } } Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null; using (this.SceneViewModel.ForceBaseValue()) { using (this.SceneViewModel.DisableDrawIntoState()) { SceneElement sceneElement1 = (SceneElement)null; SceneElement sceneElement2 = (SceneElement)activeSceneViewModel.CreateSceneNode(type); Orientation? nullable = orientationHelper.ApplyOrientation(sceneElement2); if (nullable.HasValue) { orientationHelper.SortElements(elements, nullable.Value); } int num; if (list1.Count == 1 && list1[0] is BaseFrameworkElement) { int?fixedCapacity = sceneElement2.DefaultContent.FixedCapacity; num = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false); } else { num = 0; } bool flag = num != 0; if (sceneElement2 != null) { activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true); } foreach (SceneElement sceneElement3 in list1) { if (sceneElement3 != null) { BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement; ILayoutDesigner layoutDesigner = frameworkElement == null ? (ILayoutDesigner)null : sceneElement3.ViewModel.GetLayoutDesignerForChild((SceneElement)frameworkElement, true); if (flag) { properties = SceneElementHelper.StoreProperties((SceneNode)sceneElement3, layoutDesigner.GetLayoutProperties(), true); } if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == sceneElement3) { sceneElement1 = sceneElement3; } } } if (list1.Count == 1) { VisualStateManagerSceneNode.MoveStates(list1[0], sceneElement2); } using (activeSceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { SceneElement primarySelection = designerContext.SelectionManager.ElementSelectionSet.PrimarySelection; designerContext.SelectionManager.ElementSelectionSet.Clear(); Dictionary <IPropertyId, List <SceneNode> > storedChildren = new Dictionary <IPropertyId, List <SceneNode> >(); storedChildren.Add((IPropertyId)sceneElement2.DefaultContentProperty, elements); ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer(); foreach (SceneElement sceneElement3 in list1) { if (sceneElement3 != primarySelection) { sceneElement3.Remove(); } } int index1 = collectionContainer.IndexOf((SceneNode)primarySelection); primarySelection.Remove(); collectionContainer.Insert(index1, (SceneNode)sceneElement2); ChangeLayoutTypeCommand.ApplyChildren(sceneElement2, storedChildren, empty.Size); if (flag) { SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)list1[0], (SceneNode)sceneElement2, properties); SceneElementHelper.ApplyProperties((SceneNode)sceneElement2, properties); } else { ILayoutDesigner designerForChild = sceneElement2.ViewModel.GetLayoutDesignerForChild(sceneElement2, true); if (sceneElement2.IsViewObjectValid) { LayoutOverrides layoutOverrides = LayoutOverrides.None; LayoutOverrides overridesToIgnore = LayoutOverrides.None; if (nullable.HasValue && nullable.Value == Orientation.Horizontal) { layoutOverrides |= LayoutOverrides.Width; } else { overridesToIgnore |= LayoutOverrides.Width; } if (nullable.HasValue && nullable.Value == Orientation.Vertical) { layoutOverrides |= LayoutOverrides.Height; } else { overridesToIgnore |= LayoutOverrides.Height; } designerForChild.SetChildRect((BaseFrameworkElement)sceneElement2, empty, layoutOverrides, overridesToIgnore, LayoutOverrides.None); } } editTransaction.Update(); if (sceneElement2.IsViewObjectValid) { this.SceneViewModel.DefaultView.UpdateLayout(); SceneElement parentElement = primarySelection.ParentElement; ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(parentElement, true); for (int index2 = 0; index2 < list1.Count; ++index2) { SceneElement sceneElement3 = list1[index2]; BaseFrameworkElement frameworkElement = sceneElement3 as BaseFrameworkElement; if (frameworkElement != null) { LayoutCacheRecord layoutCacheRecord = list2[index2]; Rect rect = LayoutRoundingHelper.RoundUpLayoutRect(frameworkElement, layoutCacheRecord.Rect); rect.Location = (Point)(rect.Location - empty.Location); designerForParent.ClearUnusedLayoutProperties(frameworkElement); designerForParent.SetChildRect(frameworkElement, rect, flag ? LayoutOverrides.None : layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None); if (this.IsDragDropContainer) { sceneElement3.SetValue(Base2DElement.AllowDropProperty, (object)true); } } } } if (sceneElement1 != null) { this.SceneViewModel.SetLockedInsertionPoint(sceneElement1); } } designerContext.SelectionManager.ElementSelectionSet.SetSelection(sceneElement2); editTransaction.Commit(); } } } }
private SceneNode[] Ungroup(SceneEditTransaction transaction, BaseFrameworkElement group) { SceneElement parentElement = group.ParentElement; if (parentElement == null) { return(new SceneNode[0]); } transaction.Update(); ILayoutDesigner designerForParent1 = this.SceneViewModel.GetLayoutDesignerForParent(parentElement, true); Rect childRect = designerForParent1.GetChildRect(group); Matrix effectiveRenderTransform = group.GetEffectiveRenderTransform(false); SceneNode[] array = new SceneNode[group.DefaultContent.Count]; group.DefaultContent.CopyTo(array, 0); using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { Transform[] transformArray = new Transform[array.Length]; Point[] pointArray = new Point[array.Length]; LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[array.Length]; ILayoutDesigner designerForParent2 = group.ViewModel.GetLayoutDesignerForParent((SceneElement)group, true); for (int index = 0; index < array.Length; ++index) { BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement; if (frameworkElement != null) { transformArray[index] = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty); pointArray[index] = frameworkElement.RenderTransformOrigin; designerForParent2.GetChildRect(frameworkElement); LayoutCacheRecord layoutCacheRecord = designerForParent2.CacheLayout(frameworkElement); layoutCacheRecordArray[index] = layoutCacheRecord; } } int num1; if (array.Length == 1 && array[0] is BaseFrameworkElement) { int?fixedCapacity = group.DefaultContent.FixedCapacity; num1 = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false); } else { num1 = 0; } bool flag = num1 != 0; if (flag) { Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)group, designerForParent1.GetLayoutProperties(), true); SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)group, array[0], properties); if (!SceneElementHelper.ApplyProperties(array[0], properties)) { flag = false; } } if (array.Length == 1 && array[0] is SceneElement) { VisualStateManagerSceneNode.MoveStates((SceneElement)group, (SceneElement)array[0]); } using (this.SceneViewModel.ForceBaseValue()) { SceneElement sceneElement = (SceneElement)null; for (int index = 0; index < array.Length; ++index) { BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement; if (frameworkElement != null) { if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == frameworkElement) { sceneElement = (SceneElement)frameworkElement; } DocumentNodeHelper.PreserveFormatting(frameworkElement.DocumentNode); frameworkElement.Remove(); } } ISceneNodeCollection <SceneNode> collectionContainer = group.GetCollectionContainer(); int index1 = collectionContainer.IndexOf((SceneNode)group); this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)group); this.SceneViewModel.RemoveElement((SceneNode)group); Matrix matrix1 = effectiveRenderTransform; matrix1.OffsetX = 0.0; matrix1.OffsetY = 0.0; for (int index2 = array.Length - 1; index2 >= 0; --index2) { BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement; if (frameworkElement != null) { Matrix matrix2 = (transformArray[index2] ?? Transform.Identity).Value; collectionContainer.Insert(index1, (SceneNode)frameworkElement); CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix2 * matrix1)); if (frameworkElement.GetLocalValue(Base2DElement.RenderTransformProperty) != null || !canonicalTransform.TransformGroup.Value.IsIdentity) { frameworkElement.SetValue(Base2DElement.RenderTransformProperty, canonicalTransform.GetPlatformTransform(frameworkElement.Platform.GeometryHelper)); if (frameworkElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } } } } transaction.Update(); if (sceneElement != null) { this.SceneViewModel.SetLockedInsertionPoint(sceneElement); } bool[] flagArray = new bool[array.Length]; int length = 0; for (int index2 = 0; index2 < array.Length; ++index2) { BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement; if (frameworkElement != null && array[index2].Parent != null) { if (!flag) { LayoutCacheRecord layoutCacheRecord = layoutCacheRecordArray[index2]; Rect rect1 = layoutCacheRecord.Rect; Point point1 = new Point(rect1.X + rect1.Width * pointArray[index2].X, rect1.Y + rect1.Height * pointArray[index2].Y); Point point2 = effectiveRenderTransform.Transform(point1); Rect rect2 = new Rect(rect1.TopLeft + point2 - point1 + (Vector)childRect.TopLeft, rect1.Size); designerForParent1.ClearUnusedLayoutProperties(frameworkElement); designerForParent1.SetChildRect(frameworkElement, rect2, layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None); } flagArray[index2] = true; ++length; } } SceneNode[] sceneNodeArray = new SceneNode[length]; int num2 = 0; for (int index2 = 0; index2 < array.Length; ++index2) { if (flagArray[index2]) { sceneNodeArray[num2++] = array[index2]; } } return(sceneNodeArray); } } }
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); } } } }