private bool CreateDetailsVisualization(Point dropPoint) { using (SceneEditTransaction editTransaction = this.DragModel.Document.CreateEditTransaction(StringTable.UndoUnitDragDropCreateDataboundControl)) { bool flag = true; DocumentCompositeNode containerNode = (DocumentCompositeNode)null; BaseFrameworkElement child = this.GetReusableDetailsContainer(true, this.DragModel.CheckDropFlags(DataBindingDragDropFlags.SetBinding)); if (child != null) { containerNode = (DocumentCompositeNode)child.DocumentNode; flag = false; } IList <DataSchemaNodePath> relativeSchemaPaths = this.GetRelativeSchemaPaths(); bool shouldCreateLabels = true; if (relativeSchemaPaths.Count == 1 && this.DragModel.DataSource.Count == 1 && relativeSchemaPaths[0].Node == this.DragModel.DataSource.PrimarySchemaNodePath.Node) { shouldCreateLabels = false; } CanvasLikeDataViewLayoutBuilder viewLayoutBuilder = new CanvasLikeDataViewLayoutBuilder(this.DragModel.InsertionPoint.InsertIndex, shouldCreateLabels); DocumentCompositeNode documentCompositeNode = DataViewFactory.GenerateDataView(this.DragModel.Platform, this.DragModel.DocumentContext, relativeSchemaPaths, DataViewCategory.Details, containerNode, (IDataViewLayoutBuilder)viewLayoutBuilder); if (flag) { this.DragModel.ViewModel.ElementSelectionSet.Clear(); child = (BaseFrameworkElement)this.DragModel.ViewModel.GetSceneNode((DocumentNode)documentCompositeNode); this.DragModel.InsertionPoint.Insert((SceneNode)child); this.DragModel.ViewModel.BindingEditor.CreateAndSetBindingOrData((SceneNode)child, DesignTimeProperties.DesignDataContextProperty, this.DragModel.DetailsContainerSchemaPath); } editTransaction.Update(); viewLayoutBuilder.ApplyActiveUserThemeStyle(this.DragModel.ViewModel); if (flag) { Size size = viewLayoutBuilder.CalcCombinedSize(this.DragModel.ViewModel); Rect rect = new Rect(dropPoint, new Size() { Width = Math.Max(size.Width, 200.0), Height = Math.Max(size.Height, 200.0) }); this.DragModel.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true).SetChildRect(child, rect); editTransaction.Update(); this.DragModel.ViewModel.ElementSelectionSet.SetSelection((SceneElement)child); dropPoint = new Point(); } viewLayoutBuilder.CompleteLayout(this.DragModel.ViewModel, dropPoint); if (!flag) { viewLayoutBuilder.SelectElements(this.DragModel.ViewModel); } this.LinkDetailsWithMasterControl((SceneElement)child); editTransaction.Commit(); } return(true); }
public void AddVerticalGridline(GridElement grid, double position) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitAddGridline)) { using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); int columnBeforePosition = grid.GetComputedColumnBeforePosition(position); double positionOfColumn1 = grid.GetComputedPositionOfColumn(columnBeforePosition); double positionOfColumn2 = grid.GetComputedPositionOfColumn(columnBeforePosition + 1); bool flag = grid.ColumnDefinitions.Count == 0 || grid.ColumnDefinitions[columnBeforePosition].Width.IsStar; grid.CacheComputedColumnWidths(); this.EnsureOneColumn(grid); grid.ColumnDefinitions.Insert(columnBeforePosition + 1, ColumnDefinitionNode.Factory.Instantiate(grid.ViewModel)); position = Math.Max(position, positionOfColumn1); if (position > positionOfColumn2) { grid.ComputedColumnWidthCache[columnBeforePosition] = positionOfColumn2 - positionOfColumn1; grid.ComputedColumnWidthCache.Insert(columnBeforePosition + 1, position - positionOfColumn2); } else { grid.ComputedColumnWidthCache[columnBeforePosition] = position - positionOfColumn1; grid.ComputedColumnWidthCache.Insert(columnBeforePosition + 1, positionOfColumn2 - position); } editTransaction.Update(); grid.ViewModel.DefaultView.UpdateLayout(); if (flag) { List <int> widthStarIndices = this.GetWidthStarIndices(grid); this.NormalizeWidthStars(grid, widthStarIndices); } else { grid.ColumnDefinitions[columnBeforePosition].Width = new GridLength(grid.ComputedColumnWidthCache[columnBeforePosition]); grid.ColumnDefinitions[columnBeforePosition].ClearValue(ColumnDefinitionNode.MinWidthProperty); grid.ColumnDefinitions[columnBeforePosition + 1].Width = new GridLength(grid.ComputedColumnWidthCache[columnBeforePosition + 1]); grid.ColumnDefinitions[columnBeforePosition + 1].ClearValue(ColumnDefinitionNode.MinWidthProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedColumnWidths(); editTransaction.Commit(); } } grid.ViewModel.DefaultView.AdornerLayer.InvalidateAdornersStructure((SceneElement)grid); }
public void AddHorizontalGridline(GridElement grid, double position) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitAddGridline)) { using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); int rowBeforePosition = grid.GetComputedRowBeforePosition(position); double computedPositionOfRow1 = grid.GetComputedPositionOfRow(rowBeforePosition); double computedPositionOfRow2 = grid.GetComputedPositionOfRow(rowBeforePosition + 1); bool flag = grid.RowDefinitions.Count == 0 || grid.RowDefinitions[rowBeforePosition].Height.IsStar; grid.CacheComputedRowHeights(); this.EnsureOneRow(grid); grid.RowDefinitions.Insert(rowBeforePosition + 1, RowDefinitionNode.Factory.Instantiate(grid.ViewModel)); position = Math.Max(position, computedPositionOfRow1); if (position > computedPositionOfRow2) { grid.ComputedRowHeightCache[rowBeforePosition] = computedPositionOfRow2 - computedPositionOfRow1; grid.ComputedRowHeightCache.Insert(rowBeforePosition + 1, position - computedPositionOfRow2); } else { grid.ComputedRowHeightCache[rowBeforePosition] = position - computedPositionOfRow1; grid.ComputedRowHeightCache.Insert(rowBeforePosition + 1, computedPositionOfRow2 - position); } editTransaction.Update(); grid.ViewModel.DefaultView.UpdateLayout(); if (flag) { List <int> heightStarIndices = this.GetHeightStarIndices(grid); this.NormalizeHeightStars(grid, heightStarIndices); } else { grid.RowDefinitions[rowBeforePosition].Height = new GridLength(grid.ComputedRowHeightCache[rowBeforePosition]); grid.RowDefinitions[rowBeforePosition].ClearValue(RowDefinitionNode.MinHeightProperty); grid.RowDefinitions[rowBeforePosition + 1].Height = new GridLength(grid.ComputedRowHeightCache[rowBeforePosition + 1]); grid.RowDefinitions[rowBeforePosition + 1].ClearValue(RowDefinitionNode.MinHeightProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedRowHeights(); editTransaction.Commit(); } } grid.ViewModel.DefaultView.AdornerLayer.InvalidateAdornersStructure((SceneElement)grid); }
private DocumentCompositeNode GenerateDataTemplateIfNeeded(SceneNode targetNode, ITypeId dataTemplateType) { if (this.DragModel.RelativeDropSchemaPath.IsProperty) { return((DocumentCompositeNode)null); } IList <DataSchemaNodePath> relativeSchemaPaths = this.GetRelativeSchemaPaths(); if (relativeSchemaPaths.Count == 0) { return((DocumentCompositeNode)null); } DocumentCompositeNode dataTemplateNode = (DocumentCompositeNode)null; using (SceneEditTransaction editTransaction = this.DragModel.Document.CreateEditTransaction(StringTable.UndoUnitCreateTemplate)) { DataSchemaNode node = this.DragModel.RelativeDropSchemaPath.Node; DataSchemaNode dataSchemaNode = node.CollectionItem ?? node; string str = ((dataSchemaNode.Type != (Type)null ? dataSchemaNode.Type.Name : dataSchemaNode.PathName) + "Template").TrimStart('@', '/'); if (!SceneNodeIDHelper.IsCSharpID(str)) { str = "DataTemplate"; } dataTemplateNode = DataViewFactory.CreateDataTemplateResource(targetNode, ItemsControlElement.ItemTemplateProperty, str, relativeSchemaPaths, DataViewCategory.DataTemplate, dataTemplateType); editTransaction.Update(); this.ApplyActiveUserThemeStyleToDataTemplate(dataTemplateNode); editTransaction.Commit(); } return(dataTemplateNode); }
private bool CreateControls(Point dropPoint) { using (SceneEditTransaction editTransaction = this.DragModel.Document.CreateEditTransaction(StringTable.UndoUnitDragDropCreateDataboundControl)) { DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(this.DragModel.TargetNode); DataSourceInfo other = new DataSourceInfo(new DataSchemaNodePath(this.DragModel.DataSource.PrimaryAbsoluteSchema, this.GetRelativeSchema().Root)); bool flag = false; if (dataContextInfo.DataSource == null || !dataContextInfo.DataSource.IsValidWithSource || dataContextInfo.DataSource.CompareSources(other) != DataSourceMatchCriteria.Exact) { flag = true; } IList <DataSchemaNodePath> relativeSchemaPaths = this.GetRelativeSchemaPaths(); CanvasLikeDataViewLayoutBuilder viewLayoutBuilder = new CanvasLikeDataViewLayoutBuilder(this.DragModel.InsertionPoint.InsertIndex, false); DocumentCompositeNode containerNode = (DocumentCompositeNode)this.DragModel.TargetNode.DocumentNode; DataViewFactory.GenerateDataView(this.DragModel.Platform, this.DragModel.DocumentContext, relativeSchemaPaths, DataViewCategory.Master, containerNode, (IDataViewLayoutBuilder)viewLayoutBuilder); if (flag) { viewLayoutBuilder.RebindFields(this.DragModel.ViewModel, this.DragModel.DataSource.PrimaryAbsoluteSchema, relativeSchemaPaths); } editTransaction.Update(); viewLayoutBuilder.ApplyActiveUserThemeStyle(this.DragModel.ViewModel); viewLayoutBuilder.CompleteLayout(this.DragModel.ViewModel, dropPoint); viewLayoutBuilder.SelectElements(this.DragModel.ViewModel); editTransaction.Commit(); } return(true); }
public static void AdjustPathForAnimations(PathElement pathElement, SceneEditTransaction editTransaction) { using (pathElement.ViewModel.ForceBaseValue()) { System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry)pathElement.GetLocalOrDefaultValueAsWpf(PathElement.DataProperty); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.AddGeometry(geometry1); Rect bounds = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry.Bounds, pathElement, false); PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform); Rect maxAnimatedExtent = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, propertyReference); double num1 = Math.Min(0.0, maxAnimatedExtent.Left); double num2 = Math.Min(0.0, maxAnimatedExtent.Top); Vector vector = new Vector(-num1, -num2); ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true); editTransaction.Update(); Rect childRect = designerForChild.GetChildRect((BaseFrameworkElement)pathElement); childRect.X += num1; childRect.Y += num2; childRect.Width = Math.Max(maxAnimatedExtent.Width, childRect.Width); childRect.Height = Math.Max(maxAnimatedExtent.Height, childRect.Height); designerForChild.SetChildRect((BaseFrameworkElement)pathElement, childRect); Transform transform = (Transform) new TranslateTransform(vector.X, vector.Y); PathGeometry geometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry, transform); if (!pathElement.DesignerContext.ActiveDocument.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { PathGeometryUtilities.EnsureOnlySingleSegmentsInGeometry(geometry2); } pathElement.PathGeometry = geometry2; PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform); pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1)); } }
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(); } } } } }
public override bool Handle(Point artboardSnappedDropPoint) { if (!this.ProjectContext.EnsureAssemblyReferenced("Microsoft.Expression.Interactions")) { return(false); } this.DragModel.TargetNode.DesignerContext.ViewUpdateManager.RebuildPostponedViews(); using (SceneEditTransaction editTransaction = this.DragModel.Document.CreateEditTransaction(StringTable.UndoUnitDragDropCreateDataboundControl)) { if (DataBindingModeModel.Instance.NormalizedMode == DataBindingMode.Details) { this.GetReusableDetailsContainer(true, true); editTransaction.Update(); } SceneNode actionNode; if (this.DragModel.CheckDropFlags(DataBindingDragDropFlags.CreateElement)) { IType triggerType = this.ProjectContext.ResolveType(this.DragModel.NewElementType); if (this.ProjectContext.PlatformMetadata.IsNullType((ITypeId)triggerType)) { return(false); } actionNode = TriggerActionAsset.CreateTrigger(this.DragModel.TargetNode, triggerType); editTransaction.Update(); } else { actionNode = this.DragModel.TargetNode; } if (actionNode == null) { return(false); } if (!this.DragModel.DataSource.PrimarySchemaNodePath.IsMethod ? this.UpdateInvokeCommandAction(actionNode) : this.UpdateCallMethodAction(actionNode)) { editTransaction.Commit(); return(true); } } return(false); }
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); } }
private void ReleaseClippingPath(SceneElement sceneElement, SceneEditTransaction editTransaction) { if (sceneElement.IsSet(Base2DElement.ClipProperty) != PropertyState.Set) { return; } SceneNode sceneNode = (SceneNode)sceneElement; for (SceneNode parent = sceneElement.Parent; parent != null; parent = parent.Parent) { PanelElement panelElement = parent as PanelElement; if (panelElement != null) { MatrixTransform matrixTransform = new MatrixTransform(sceneElement.GetComputedTransformToElement((SceneElement)panelElement)); PathGeometry pathGeometry1 = new PathGeometry(); System.Windows.Media.Geometry geometry = (System.Windows.Media.Geometry)sceneElement.GetLocalOrDefaultValueAsWpf(Base2DElement.ClipProperty); if (geometry != null) { pathGeometry1 = PathGeometryUtilities.TransformGeometry(geometry, (Transform)matrixTransform); } PathElement pathElement = (PathElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Path); using (pathElement.ViewModel.ForceBaseValue()) { this.DesignerContext.AmbientPropertyManager.ApplyAmbientProperties((SceneNode)pathElement); pathElement.SetValueAsWpf(ShapeElement.StrokeProperty, (object)Brushes.Black); pathElement.ClearValue(ShapeElement.FillProperty); pathElement.ClearValue(ShapeElement.StrokeThicknessProperty); panelElement.Children.Insert(panelElement.Children.IndexOf(sceneNode) + 1, (SceneNode)pathElement); ReferenceStep singleStep1 = (ReferenceStep)pathElement.ProjectContext.ResolveProperty(Base2DElement.ClipProperty); ReferenceStep singleStep2 = (ReferenceStep)pathElement.ProjectContext.ResolveProperty(PathElement.DataProperty); PathCommandHelper.MoveVertexAnimations(sceneElement, new PropertyReference(singleStep1), (SceneElement)pathElement, new PropertyReference(singleStep2), (Transform)matrixTransform); Rect bounds = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false); Rect maxAnimatedExtent = PathCommandHelper.FindMaxAnimatedExtent((SceneElement)pathElement, bounds, new PropertyReference(singleStep2)); editTransaction.Update(); Vector vector = new Vector(-maxAnimatedExtent.Left, -maxAnimatedExtent.Top); panelElement.LayoutDesigner.SetChildRect((BaseFrameworkElement)pathElement, maxAnimatedExtent); Transform transform = (Transform) new TranslateTransform(vector.X, vector.Y); PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform); pathElement.PathGeometry = pathGeometry2; PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, new PropertyReference(singleStep2), transform); pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)(Stretch)(pathElement.HasVertexAnimations ? 0 : 1)); break; } } else { sceneNode = parent; } } }
public void RemoveRow(GridElement grid, int index) { using (SceneEditTransaction editTransaction = grid.ViewModel.CreateEditTransaction(StringTable.UndoUnitRemoveGridline)) { grid.ViewModel.GridRowSelectionSet.Clear(); grid.ViewModel.AnimationEditor.DeleteAllAnimations((SceneNode)grid.RowDefinitions[index]); using (grid.ViewModel.ForceBaseValue()) { List <LayoutCacheRecord> currentRects = this.GetCurrentRects((BaseFrameworkElement)grid); bool isStar1 = grid.RowDefinitions[index - 1].Height.IsStar; bool isStar2 = grid.RowDefinitions[index].Height.IsStar; List <int> heightStarIndices = this.GetHeightStarIndices(grid); grid.CacheComputedRowHeights(); List <double> computedRowHeightCache; int index1; (computedRowHeightCache = grid.ComputedRowHeightCache)[index1 = index - 1] = computedRowHeightCache[index1] + grid.ComputedRowHeightCache[index]; grid.ComputedRowHeightCache.RemoveAt(index); grid.RowDefinitions.RemoveAt(index); if (isStar2) { heightStarIndices.Remove(index); } if (isStar1 || isStar2) { for (int index2 = 0; index2 < heightStarIndices.Count; ++index2) { if (heightStarIndices[index2] > index) { List <int> list; int index3; (list = heightStarIndices)[index3 = index2] = list[index3] - 1; } } this.NormalizeHeightStars(grid, heightStarIndices); } if (!isStar1) { grid.RowDefinitions[index - 1].Height = new GridLength(grid.ComputedRowHeightCache[index - 1]); grid.RowDefinitions[index - 1].ClearValue(RowDefinitionNode.MinHeightProperty); } editTransaction.Update(); grid.ViewModel.RefreshSelection(); this.SetCurrentRects((BaseFrameworkElement)grid, currentRects); grid.UncacheComputedRowHeights(); GridLayoutDesigner.ReselectGridToRestoreAdorners(grid); editTransaction.Commit(); } } }
private void SerializeAsInlines() { DocumentCompositeNode documentCompositeNode1 = (DocumentCompositeNode)this.TextSource.DocumentNode; if (this.FlowDocumentNode != null) { DocumentCompositeNode documentCompositeNode2 = (DocumentCompositeNode)this.FlowDocumentNode.Properties[FlowDocumentElement.BlocksProperty]; DocumentCompositeNode documentCompositeNode3 = (DocumentCompositeNode)documentCompositeNode2.Children[0]; using (this.TextSource.ViewModel.AnimationEditor.DeferKeyFraming()) { using (SceneEditTransaction editTransaction = this.TextSource.ViewModel.CreateEditTransaction(StringTable.TextEditUndo)) { DocumentCompositeNode node = documentCompositeNode1.Context.CreateNode(typeof(InlineCollection)); Block block = ((FlowDocument)this.RichTextBox.Document.PlatformSpecificObject).Blocks.FirstBlock; for (int index = 0; index < documentCompositeNode2.Children.Count; ++index) { foreach (Microsoft.Expression.DesignModel.DocumentModel.DocumentNode documentNode in this.BuildInlinesFromBlock(documentCompositeNode2.Children[index], block)) { node.Children.Add(documentNode); } if (index < documentCompositeNode2.Children.Count - 1) { node.Children.Add((Microsoft.Expression.DesignModel.DocumentModel.DocumentNode)node.Context.CreateNode(typeof(LineBreak))); } block = block.NextBlock; } this.StripUnsupportedElements(node); this.TextSource.ClearLocalValue(TextBlockElement.TextProperty); editTransaction.Update(); documentCompositeNode1.Properties[TextBlockElement.InlinesProperty] = (Microsoft.Expression.DesignModel.DocumentModel.DocumentNode)node; editTransaction.Commit(); } } } else { using (this.TextSource.ViewModel.AnimationEditor.DeferKeyFraming()) { using (SceneEditTransaction editTransaction = this.TextSource.ViewModel.CreateEditTransaction(StringTable.TextEditUndo)) { this.StripUnsupportedElements(this.InlinesCollectionNode); this.TextSource.ClearLocalValue(TextBlockElement.TextProperty); editTransaction.Update(); documentCompositeNode1.Properties[TextBlockElement.InlinesProperty] = (Microsoft.Expression.DesignModel.DocumentModel.DocumentNode) this.InlinesCollectionNode; editTransaction.Commit(); } } } }
private DataStoreReferenceEntry CreateNewDataStore(SceneEditTransaction transation) { SampleDataSet sampleDataSet = this.ProjectXamlContext.SampleData.CreateSampleDataSet(DataSetContext.DataStore, "DataStore", true); sampleDataSet.Save(); this.ObjectSet.ViewModel.DataPanelModel.AddDataStoreDataSource(sampleDataSet, true); transation.Update(); IEnumerable <DataStoreReferenceEntry> dataStoreDataSet = this.FindDataStoreDataSet((Predicate <SampleDataSet>)(dataSet => true)); if (dataStoreDataSet != null) { return(Enumerable.FirstOrDefault <DataStoreReferenceEntry>(dataStoreDataSet)); } return((DataStoreReferenceEntry)null); }
public static IDisposable TurnOffLayoutRounding(BaseFrameworkElement element) { IViewVisual viewVisual = element.ViewObject as IViewVisual; IProperty propertyKey = element.ProjectContext.ResolveProperty(Base2DElement.UseLayoutRoundingProperty); if (propertyKey == null || viewVisual == null || !(bool)viewVisual.GetCurrentValue(propertyKey)) { return((IDisposable)null); } SceneEditTransaction editTransaction = element.ViewModel.CreateEditTransaction("TurnOffLayoutRounding", true); element.SetValue((IPropertyId)propertyKey, (object)false); editTransaction.Update(); viewVisual.UpdateLayout(); return((IDisposable)editTransaction); }
private static void CreateAndSetElementNameBinding(string propertyName, SceneNode node, Action <BindingSceneNode> setValue) { string description = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertyChangeUndoDescription, new object[1] { (object)propertyName }); SceneViewModel viewModel = node.ViewModel; using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(description)) { node.EnsureNamed(); editTransaction.Update(); BindingSceneNode bindingSceneNode = viewModel.CreateSceneNode(PlatformTypes.Binding) as BindingSceneNode; bindingSceneNode.ElementName = node.Name; setValue(bindingSceneNode); editTransaction.Commit(); } }
private void SerializeAsTextProperty() { using (this.TextSource.ViewModel.AnimationEditor.DeferKeyFraming()) { using (SceneEditTransaction editTransaction = this.TextSource.ViewModel.CreateEditTransaction(StringTable.TextEditUndo)) { string str = string.Empty; Block firstBlock = ((FlowDocument)this.RichTextBox.Document.PlatformSpecificObject).Blocks.FirstBlock; if (firstBlock != null) { str = new TextRange(firstBlock.ContentStart, firstBlock.ContentEnd).Text; } this.TextSource.ClearLocalValue(TextBlockElement.InlinesProperty); editTransaction.Update(); this.TextSource.SetValue(TextBlockElement.TextProperty, (object)str); editTransaction.Commit(); } } }
public override void Execute() { using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitEditStyleTemplate, new object[1] { (object)this.TargetPropertyReference.Path }), 1 != 0)) { this.SceneView.CandidateEditingContainer = this.TargetElement.DocumentNodePath; editTransaction.Update(); DocumentNodePath templateNodePath = this.StyleOrTemplateNodePath; this.SceneView.CandidateEditingContainer = (DocumentNodePath)null; if (templateNodePath != null) { bool preferInPlaceEdit = ControlStylingOperations.CanEditInPlace(this.TargetElement, this.TargetProperty, templateNodePath); ControlStylingOperations.SetActiveEditingContainer(this.TargetElement, this.TargetProperty, templateNodePath.Node, templateNodePath, preferInPlaceEdit, editTransaction); } editTransaction.Commit(); } }
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(); } }
private void DeleteStateGroup() { if (this.ActiveSceneViewModel == null) { return; } using (SceneEditTransaction editTransaction = this.sceneNode.ViewModel.CreateEditTransaction(StringTable.DeleteVisualStateGroupUndoUnit)) { if (this.selectedState != null || this.IsSelectedWithin) { this.SelectState((StateModel)null); } VisualStateManagerSceneNode.DeleteStateGroup(this.ModelManager.TargetNode, this.sceneNode); editTransaction.Update(); if (this.ActiveSceneViewModel != null) { VisualStateManagerSceneNode.UpdateHasExtendedVisualStateManager(this.ActiveSceneViewModel.ActiveEditingContainer); } editTransaction.Commit(); } }
public override void SelectElement(SceneElement element, SceneNodeProperty editingProperty) { if (element == null || editingProperty == null || (editingProperty.SceneNodeObjectSet == null || editingProperty.IsMixedValue)) { return; } SceneNodeObjectSet sceneNodeObjectSet = editingProperty.SceneNodeObjectSet; BindingSceneNode bindingSceneNode = sceneNodeObjectSet.ViewModel.CreateSceneNode(PlatformTypes.Binding) as BindingSceneNode; LayoutPathNode layoutPathNode = sceneNodeObjectSet.ViewModel.CreateSceneNode(ProjectNeutralTypes.LayoutPath) as LayoutPathNode; using (SceneEditTransaction editTransaction = sceneNodeObjectSet.ViewModel.CreateEditTransaction(StringTable.AddLayoutPathUndo)) { using (sceneNodeObjectSet.ViewModel.ForceBaseValue()) { element.EnsureNamed(); editTransaction.Update(); bindingSceneNode.ElementName = element.Name; layoutPathNode.SetValue(LayoutPathNode.SourceElementProperty, (object)bindingSceneNode.DocumentNode); editingProperty.AddValue((object)layoutPathNode.DocumentNode); editTransaction.Commit(); } } }
public void OnDoubleClickItem(PartInPartsExplorer part) { SceneElement selectionToSet = (SceneElement)null; if (part.Status != PartStatus.Unused) { selectionToSet = this.viewModel.GetSceneNode(this.viewModel.ActiveEditingContainer.DocumentNode.NameScope.FindNode(part.Name)) as SceneElement; } else { using (SceneEditTransaction editTransaction = this.viewModel.CreateEditTransaction(StringTable.UndoDoubleClickToMakePart, false)) { KeyValuePair <ITypeId, ITypeId> keyValuePair = Enumerable.FirstOrDefault <KeyValuePair <ITypeId, ITypeId> >((IEnumerable <KeyValuePair <ITypeId, ITypeId> >)PartsModel.instanceTypesForAbstractParts, (Func <KeyValuePair <ITypeId, ITypeId>, bool>)(pair => pair.Key.Equals((object)part.TargetType))); BaseFrameworkElement frameworkElement = keyValuePair.Key == null ? (BaseFrameworkElement)this.viewModel.CreateSceneNode(part.TargetType) : (BaseFrameworkElement)this.viewModel.CreateSceneNode(keyValuePair.Value); frameworkElement.Name = part.Name; this.viewModel.ActiveSceneInsertionPoint.Insert((SceneNode)frameworkElement); selectionToSet = (SceneElement)frameworkElement; editTransaction.Update(); if (frameworkElement.IsViewObjectValid) { editTransaction.Commit(); } else { editTransaction.Cancel(); selectionToSet = (SceneElement)null; } } } if (selectionToSet == null || !PlatformTypes.UIElement.IsAssignableFrom((ITypeId)selectionToSet.Type)) { return; } this.viewModel.ClearSelections(); this.viewModel.ElementSelectionSet.SetSelection(selectionToSet); this.viewModel.TimelineItemManager.EnsureExpandedAncestors(this.viewModel.TimelineItemManager.FindTimelineItem((SceneNode)selectionToSet)); }
public static SceneNode SetActiveEditingContainer(SceneElement targetElement, ReferenceStep targetProperty, DocumentNode node, DocumentNodePath knownPath, bool preferInPlaceEdit, SceneEditTransaction outerTransaction) { ControlStylingOperations.EditScope scope = new ControlStylingOperations.EditScope() { TargetElement = targetElement, TargetProperty = targetProperty, Node = node, NodePath = knownPath, EditInPlace = preferInPlaceEdit }; SceneNode sceneNode = (SceneNode)null; ControlStylingOperations.EditScope templateScope; ControlStylingOperations.EditScope styleScope; if (ControlStylingOperations.ShouldNavigateToIntermediateStyle(scope, out templateScope, out styleScope)) { templateScope.TargetElement = ControlStylingOperations.SetActiveEditingContainerInternal(styleScope) as SceneElement; if (templateScope.TargetElement != null) { templateScope.TargetElement.ViewModel.EditContextManager.ActiveEditContext.EnsureHidden(); if (outerTransaction != null) { outerTransaction.Update(); } if (ControlStylingOperations.UpdateNavigationInfo(templateScope)) { sceneNode = ControlStylingOperations.SetActiveEditingContainerInternal(templateScope); } } } if (sceneNode == null) { sceneNode = ControlStylingOperations.SetActiveEditingContainerInternal(scope); } return(sceneNode); }
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(); } } } }
protected override IList <SceneElement> AddToDocumentInternal(string importedFilePath, SceneElement element, ISceneInsertionPoint insertionPoint, SceneViewModel sceneViewModel, SceneEditTransaction editTransaction) { MediaSceneElement mediaSceneElement = element as MediaSceneElement; IList <SceneElement> list = (IList <SceneElement>) new List <SceneElement>(); if (mediaSceneElement != null) { double num = (double)mediaSceneElement.GetLocalOrDefaultValueAsWpf(DesignTimeProperties.DesignTimeNaturalDurationProperty); mediaSceneElement.ClearLocalValue(DesignTimeProperties.DesignTimeNaturalDurationProperty); if (insertionPoint.CanInsert((ITypeId)mediaSceneElement.Type)) { if (!JoltHelper.TypeSupported((ITypeResolver)element.ProjectContext, PlatformTypes.MediaTimeline)) { Uri uri = new Uri(importedFilePath, UriKind.RelativeOrAbsolute); mediaSceneElement.SetLocalValueAsWpf(MediaSceneElement.SourceProperty, (object)uri); } else { IStoryboardContainer mediaStoryboardContainer = insertionPoint.SceneNode.StoryboardContainer; StoryboardTimelineSceneNode targetStoryboard = (StoryboardTimelineSceneNode)null; sceneViewModel.EditContextManager.SingleViewModelEditContextWalker.Walk(false, (SingleHistoryCallback)((context, isGhosted) => { if (context.StoryboardContainer != mediaStoryboardContainer) { return(false); } targetStoryboard = context.Timeline; return(true); })); if (targetStoryboard == null) { foreach (TriggerBaseNode triggerBaseNode in (IEnumerable <TriggerBaseNode>)mediaStoryboardContainer.VisualTriggers) { EventTriggerNode eventTriggerNode = triggerBaseNode as EventTriggerNode; if (eventTriggerNode != null && eventTriggerNode.RoutedEvent == FrameworkElement.LoadedEvent) { foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)eventTriggerNode.Actions) { TimelineActionNode timelineActionNode = sceneNode as TimelineActionNode; if (timelineActionNode != null && timelineActionNode.TimelineOperation == TimelineOperation.Begin) { targetStoryboard = timelineActionNode.TargetTimeline; if (!TimelinePane.ShouldExposeStoryboardToUser((SceneNode)targetStoryboard)) { targetStoryboard = (StoryboardTimelineSceneNode)null; } else { break; } } } } if (targetStoryboard != null) { break; } } if (targetStoryboard != null) { sceneViewModel.SetActiveStoryboardTimeline(mediaStoryboardContainer, targetStoryboard, (TriggerBaseNode)null); } } if (targetStoryboard == null) { targetStoryboard = sceneViewModel.AnimationEditor.CreateNewTimeline(sceneViewModel.ActiveStoryboardContainer, element.Name, TriggerCreateBehavior.Default, true); sceneViewModel.AnimationEditor.IsRecording = false; } IType type = this.DesignerContext.ActiveDocument.ProjectContext.ResolveType(PlatformTypes.MediaTimeline); MediaTimelineSceneNode timelineSceneNode = (MediaTimelineSceneNode)sceneViewModel.CreateSceneNode(type.RuntimeType); timelineSceneNode.SetLocalValue(DesignTimeProperties.DesignTimeNaturalDurationProperty, (object)num); Uri uri = new Uri(importedFilePath, UriKind.RelativeOrAbsolute); timelineSceneNode.Source = uri; timelineSceneNode.TargetName = element.Name; double animationTime = sceneViewModel.AnimationEditor.AnimationTime; timelineSceneNode.Begin = animationTime; targetStoryboard.Children.Add((TimelineSceneNode)timelineSceneNode); editTransaction.Update(); } list.Add(element); insertionPoint.Insert((SceneNode)mediaSceneElement); } } return(list); }
public override void Execute() { SceneElement targetElement = this.TargetElement; if (targetElement is StyleNode) { this.useStyle = new bool?(false); } else { IList <DocumentCompositeNode> auxillaryResources1; DocumentNode documentNode1 = this.ProvideCurrentStyle(targetElement, this.Type, new PropertyReference((ReferenceStep)targetElement.ProjectContext.ResolveProperty(BaseFrameworkElement.StyleProperty)), false, out auxillaryResources1); IList <DocumentCompositeNode> auxillaryResources2; DocumentNode other = this.ProvideCurrentTemplate(targetElement, new PropertyReference(this.ActiveTemplateProperty), out auxillaryResources2); bool flag = false; if ((other == null || other.DocumentRoot == null) && documentNode1 != null) { using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitEditCopyStyle, true)) { if (auxillaryResources1 != null && auxillaryResources1.Count > 0) { ResourceSite resourceSite = new ResourceSite(targetElement.DocumentNode); resourceSite.EnsureResourceCollection(); foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources1) { DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(entryNode); DocumentNode documentNode2 = entryNode.Properties[DictionaryEntryNode.ValueProperty]; if (resourceEntryKey != null && documentNode2 != null) { DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.DictionaryEntry); dictionaryEntryNode.KeyNode = this.SceneViewModel.GetSceneNode(resourceEntryKey.Clone(this.SceneViewModel.Document.DocumentContext)); dictionaryEntryNode.Value = this.SceneViewModel.GetSceneNode(documentNode2.Clone(this.SceneViewModel.Document.DocumentContext)); resourceSite.ResourcesDictionary.Children.Add(dictionaryEntryNode.DocumentNode); } } } documentNode1 = documentNode1.Clone(this.SceneViewModel.Document.DocumentContext); DocumentCompositeNode documentCompositeNode = documentNode1 as DocumentCompositeNode; if (documentCompositeNode != null && documentCompositeNode.NameProperty != null && documentCompositeNode.Properties.Contains(documentCompositeNode.NameProperty)) { documentCompositeNode.ClearValue((IPropertyId)documentCompositeNode.NameProperty); } targetElement.SetValue(this.TargetPropertyReference, (object)documentNode1); DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(this.TargetPropertyReference); documentNode1 = valueAsDocumentNode != null ? valueAsDocumentNode.Node : (DocumentNode)null; editTransaction.Update(); object computedValue = targetElement.GetComputedValue(new PropertyReference(this.ActiveTemplateProperty)); if (computedValue != null) { DocumentNodePath correspondingNodePath = this.SceneView.GetCorrespondingNodePath(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(computedValue), true); if (correspondingNodePath != null) { flag = valueAsDocumentNode.IsAncestorOf(correspondingNodePath); other = correspondingNodePath != null ? correspondingNodePath.Node : other; } } editTransaction.Cancel(); } } this.useStyle = new bool?(flag || other != null && documentNode1 != null && documentNode1.IsAncestorOf(other)); } base.Execute(); this.useStyle = new bool?(); }
public static Transform ReplacePathGeometry(PathElement pathElement, PathGeometry pathGeometry, SceneEditTransaction editTransaction) { Transform transform1 = Transform.Identity; using (pathElement.ViewModel.ForceBaseValue()) { if (pathGeometry == null) { pathElement.ClearLocalValue(PathElement.DataProperty); } else { editTransaction.Update(); ILayoutDesigner designerForChild = pathElement.ViewModel.GetLayoutDesignerForChild((SceneElement)pathElement, true); Rect childRect = designerForChild.GetChildRect((BaseFrameworkElement)pathElement); Path path = pathElement.Path; Transform transform2 = path == null ? (Transform)null : path.RenderTransform; Point point1 = path == null ? new Point(0.0, 0.0) : path.RenderTransformOrigin; double num = path == null || path.Stroke == null ? 0.0 : path.StrokeThickness; Rect bounds = pathGeometry.Bounds; PathGeometry pathGeometry1 = new PathGeometry(); pathGeometry1.AddGeometry((System.Windows.Media.Geometry)pathGeometry); Rect rect1 = PathCommandHelper.InflateRectByStrokeWidth(pathGeometry1.Bounds, pathElement, false); Vector vector1 = new Vector(-rect1.Left, -rect1.Top); transform1 = (Transform) new TranslateTransform(vector1.X, vector1.Y); PathGeometry pathGeometry2 = PathGeometryUtilities.TransformGeometry((System.Windows.Media.Geometry)pathGeometry1, transform1); pathElement.PathGeometry = pathGeometry2; PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform); PathCommandHelper.TransformPointKeyframes((SceneElement)pathElement, propertyReference, transform1); if (!bounds.IsEmpty) { bounds.Inflate(num / 2.0, num / 2.0); Rect rect2 = new Rect(childRect.Left + bounds.Left, childRect.Top + bounds.Top, bounds.Width, bounds.Height); editTransaction.Update(); designerForChild.SetChildRect((BaseFrameworkElement)pathElement, rect2); if (pathElement.IsSet(Base2DElement.RenderTransformOriginProperty) != PropertyState.Set) { if (transform2 != null) { if (transform2.Value.IsIdentity) { goto label_15; } } else { goto label_15; } } Vector vector2 = childRect.TopLeft + new Vector(point1.X * childRect.Width, point1.Y * childRect.Height) - rect2.TopLeft; Point point2 = new Point(0.0, 0.0); if (rect2.Width != 0.0) { point2.X = vector2.X / rect2.Width; } if (rect2.Height != 0.0) { point2.Y = vector2.Y / rect2.Height; } pathElement.RenderTransformOrigin = point2; } } } label_15: return(transform1); }
public override void Execute(object arg) { ITypeId type = this.Type; if (type is ProjectNeutralTypeId && !this.SceneViewModel.ProjectContext.PlatformMetadata.IsSupported((ITypeResolver)this.SceneViewModel.ProjectContext, type)) { return; } using (SceneEditTransaction editTransaction = this.DesignerContext.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.UndoUnitLayoutPaneChangeLayoutType, new object[1] { (object)this.Type.Name }))) { bool flag1 = false; SceneViewModel activeSceneViewModel = this.DesignerContext.ActiveSceneViewModel; ReadOnlyCollection <SceneElement> selection = this.DesignerContext.SelectionManager.ElementSelectionSet.Selection; SceneElement primarySelection1 = this.DesignerContext.SelectionManager.ElementSelectionSet.PrimarySelection; List <SceneElement> list = new List <SceneElement>(); bool flag2 = false; bool flag3 = false; bool flag4 = false; SceneElement sceneElement1 = (SceneElement)null; IStoryboardContainer storyboardContainer = (IStoryboardContainer)null; SceneElement primarySelection2 = (SceneElement)null; this.DesignerContext.SelectionManager.ElementSelectionSet.Clear(); List <SceneElement> elements = new List <SceneElement>(); elements.AddRange((IEnumerable <SceneElement>)selection); ElementUtilities.SortElementsByDepth(elements); foreach (SceneElement sceneElement2 in elements) { ITypeId typeId1 = (ITypeId)null; foreach (ITypeId typeId2 in ChangeLayoutTypeFlyoutCommand.LayoutTypes) { if (typeId2.IsAssignableFrom((ITypeId)sceneElement2.Type)) { typeId1 = typeId2; break; } } if (typeId1 == null) { list.Add(sceneElement2); } else { if (activeSceneViewModel.LockedInsertionPoint != null) { if (activeSceneViewModel.LockedInsertionPoint.SceneElement == sceneElement2) { flag2 = true; } else if (sceneElement2.IsAncestorOf((SceneNode)activeSceneViewModel.ActiveSceneInsertionPoint.SceneElement)) { sceneElement1 = activeSceneViewModel.ActiveSceneInsertionPoint.SceneElement; flag2 = true; } } if (primarySelection1 == sceneElement2) { flag4 = true; } if (!flag3 && activeSceneViewModel.ActiveStoryboardContainer == sceneElement2) { activeSceneViewModel.SetActiveStoryboardTimeline((IStoryboardContainer)null, (StoryboardTimelineSceneNode)null, (TriggerBaseNode)null); flag3 = true; } using (sceneElement2.ViewModel.ForceBaseValue()) { BaseFrameworkElement parent1 = sceneElement2 as BaseFrameworkElement; List <LayoutCacheRecord> layoutCache = (List <LayoutCacheRecord>)null; ILayoutDesigner designerForParent = activeSceneViewModel.GetLayoutDesignerForParent(sceneElement2, true); if (parent1 != null) { layoutCache = designerForParent.GetCurrentRects(parent1); } SceneElement elementContainingChildren = (SceneElement)null; SceneElement sceneElement3 = ChangeLayoutTypeCommand.ChangeLayoutType(sceneElement2, type, ref elementContainingChildren); editTransaction.Update(); if (sceneElement3.IsViewObjectValid) { this.SceneViewModel.DefaultView.UpdateLayout(); BaseFrameworkElement parent2 = elementContainingChildren as BaseFrameworkElement; if (parent2 != null && parent2.IsViewObjectValid && layoutCache != null) { activeSceneViewModel.GetLayoutDesignerForParent(elementContainingChildren, true).SetCurrentRects(parent2, layoutCache); } if (flag2 && sceneElement1 == null) { sceneElement1 = elementContainingChildren; } if (flag3 && storyboardContainer == null) { storyboardContainer = (IStoryboardContainer)sceneElement3; } if (flag4 && primarySelection2 == null) { primarySelection2 = sceneElement3; } list.Add(sceneElement3); } flag1 = true; } } } if (flag2 && sceneElement1 != null) { activeSceneViewModel.SetLockedInsertionPoint(sceneElement1); } if (flag3 && storyboardContainer != null) { activeSceneViewModel.SetActiveStoryboardTimeline(storyboardContainer, (StoryboardTimelineSceneNode)null, (TriggerBaseNode)null); } this.DesignerContext.SelectionManager.ElementSelectionSet.SetSelection((ICollection <SceneElement>)list, primarySelection2); if (flag1) { editTransaction.Commit(); } else { editTransaction.Cancel(); } } }
private void SetLayout(ISceneInsertionPoint insertionPoint, Rect rect, SceneNode node, SceneNode layoutTarget, SceneEditTransaction undo) { if (!PlatformTypes.UIElement.IsAssignableFrom((ITypeId)node.Type)) { return; } bool flag1 = false; bool flag2 = false; if (node.IsSet(BaseFrameworkElement.WidthProperty) == PropertyState.Set && double.IsNaN(rect.Width)) { rect.Width = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.WidthProperty); flag1 = true; } if (node.IsSet(BaseFrameworkElement.HeightProperty) == PropertyState.Set && double.IsNaN(rect.Height)) { rect.Height = (double)node.GetLocalOrDefaultValueAsWpf(BaseFrameworkElement.HeightProperty); flag2 = true; } using (this.ViewModel.ForceBaseValue()) { BaseFrameworkElement child = layoutTarget as BaseFrameworkElement; if (child == null) { return; } SetRectMode setRectMode = SetRectMode.Default; ILayoutDesigner designerForChild = child.ViewModel.GetLayoutDesignerForChild((SceneElement)child, true); if (double.IsNaN(rect.Width) || double.IsNaN(rect.Height)) { setRectMode = SetRectMode.CreateDefault; bool flag3 = PlatformTypes.Control.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.TextBlock.IsAssignableFrom((ITypeId)node.Type); for (int index = 0; index < DefaultTypeInstantiator.SizeNonExceptions.Length; ++index) { if (DefaultTypeInstantiator.SizeNonExceptions[index].Equals((object)node.Type)) { flag3 = false; } } if (!flag3) { BaseFrameworkElement frameworkElement = insertionPoint.SceneNode as BaseFrameworkElement; if (frameworkElement != null) { Rect computedTightBounds = frameworkElement.GetComputedTightBounds(); double val1_1 = 100.0; double val1_2 = 100.0; if (ProjectNeutralTypes.GridSplitter.IsAssignableFrom((ITypeId)node.Type)) { val1_1 = 5.0; } else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type)) { val1_1 = 75.0; } else if (PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type)) { val1_1 = 120.0; } if (PlatformTypes.ProgressBar.IsAssignableFrom((ITypeId)node.Type)) { val1_2 = 10.0; } else if (PlatformTypes.Button.IsAssignableFrom((ITypeId)node.Type) || PlatformTypes.ComboBox.IsAssignableFrom((ITypeId)node.Type)) { val1_2 = double.NaN; } if ((designerForChild.GetWidthConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike) { val1_1 = Math.Min(val1_1, computedTightBounds.Width); } if ((designerForChild.GetHeightConstraintMode(child) & LayoutConstraintMode.CanvasLike) == LayoutConstraintMode.NonOverlappingGridlike) { val1_2 = Math.Min(val1_2, computedTightBounds.Height); } rect = new Rect(rect.Left, rect.Top, double.IsNaN(rect.Width) ? val1_1 : rect.Width, double.IsNaN(rect.Height) ? val1_2 : rect.Height); } } } LayoutOverrides layoutOverrides = LayoutOverrides.None; LayoutOverrides overridesToIgnore = LayoutOverrides.None; Rect rect1 = rect; if (double.IsNaN(rect.Width)) { layoutOverrides |= LayoutOverrides.Width; rect1.Width = 0.0; } else { overridesToIgnore |= LayoutOverrides.Width; } if (double.IsNaN(rect.Height)) { layoutOverrides |= LayoutOverrides.Height; rect1.Height = 0.0; } else { overridesToIgnore |= LayoutOverrides.Height; } designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, LayoutOverrides.None, setRectMode); undo.Update(); IViewVisual viewVisual = child.ViewObject as IViewVisual; if (viewVisual == null || !double.IsNaN(rect.Width) && !double.IsNaN(rect.Height)) { return; } viewVisual.UpdateLayout(); Rect childRect = designerForChild.GetChildRect(child); if (double.IsNaN(rect.Width) && !flag1) { if (viewVisual.RenderSize.Width < 5.0) { rect1.Width = 100.0; layoutOverrides &= ~LayoutOverrides.Width; overridesToIgnore |= LayoutOverrides.Width; } else { rect1.Width = childRect.Width; } } if (double.IsNaN(rect.Height) && !flag2) { if (viewVisual.RenderSize.Height < 5.0) { rect1.Height = 100.0; layoutOverrides &= ~LayoutOverrides.Height; overridesToIgnore |= LayoutOverrides.Height; } else { rect1.Height = childRect.Height; } } LayoutOverrides nonExplicitOverrides = LayoutOverrides.None; if (PlatformTypes.FlowDocumentScrollViewer.IsAssignableFrom((ITypeId)child.Type) || PlatformTypes.RichTextBox.IsAssignableFrom((ITypeId)child.Type)) { nonExplicitOverrides = LayoutOverrides.Width; } designerForChild.SetChildRect(child, rect1, layoutOverrides, overridesToIgnore, nonExplicitOverrides, setRectMode); } }
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 override void Execute() { BaseFrameworkElement selectedElement = this.SelectedElement; if (selectedElement == null) { return; } IType type1 = this.SceneViewModel.ProjectContext.ResolveType(PlatformTypes.Style); CreateResourceModel.ContextFlags contextFlags = this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles) ? CreateResourceModel.ContextFlags.CanApplyAutomatically : CreateResourceModel.ContextFlags.None; if (this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles)) { contextFlags = CreateResourceModel.ContextFlags.CanApplyAutomatically; } CreateResourceModel createResourceModel = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, type1.RuntimeType, this.DefaultContainerType.RuntimeType, PlatformTypes.Style.Name, (SceneElement)null, (SceneNode)selectedElement, contextFlags); if (this.ShowUI) { bool?nullable = this.CreateDialog(createResourceModel).ShowDialog(); if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0) { return; } } using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { using (SceneEditTransaction editTransaction1 = this.SceneViewModel.CreateEditTransaction(this.UndoString, false)) { using (this.SceneViewModel.ForceBaseValue()) { using (this.SceneViewModel.DisableDrawIntoState()) { this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)selectedElement); this.SceneViewModel.ElementSelectionSet.Clear(); IDocumentContext documentContext = this.SceneViewModel.Document.DocumentContext; IProjectContext projectContext = this.SceneViewModel.Document.ProjectContext; Type type2 = (Type)null; if (createResourceModel.TargetTypeAsset != null && createResourceModel.TargetTypeAsset.EnsureTypeReferenced(this.SceneViewModel.ProjectContext as ProjectContext)) { type2 = createResourceModel.TargetTypeAsset.Type.RuntimeType; } if (type2 == (Type)null) { type2 = createResourceModel.TargetType; } IType type3 = projectContext.GetType(type2); DocumentCompositeNode documentCompositeNode1 = (DocumentCompositeNode)selectedElement.DocumentNode; this.SceneViewModel.GetLayoutDesignerForChild((SceneElement)selectedElement, true).ClearUnusedLayoutProperties(selectedElement); DocumentCompositeNode visualTreeNode = documentContext.CreateNode((ITypeId)documentCompositeNode1.Type); Dictionary <IProperty, DocumentNode> dictionary = new Dictionary <IProperty, DocumentNode>(); bool addRenderTransforms = false; foreach (IPropertyId propertyId in this.GetLayoutProperties((SceneElement)selectedElement, addRenderTransforms)) { IProperty property = this.DesignerContext.ActiveSceneViewModel.ProjectContext.ResolveProperty(propertyId); if (property != null && documentCompositeNode1.Properties.Contains(property)) { dictionary.Add(property, documentCompositeNode1.Properties[(IPropertyId)property].Clone(documentContext)); documentCompositeNode1.ClearValue((IPropertyId)property); } } foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode1.Properties) { IPropertyId index = (IPropertyId)keyValuePair.Key; DependencyPropertyReferenceStep propertyReferenceStep = index as DependencyPropertyReferenceStep; if ((propertyReferenceStep == null || !propertyReferenceStep.IsAttachable || propertyReferenceStep.MemberType == MemberType.DesignTimeProperty) && (!index.Equals((object)BaseFrameworkElement.WidthProperty) && !index.Equals((object)BaseFrameworkElement.HeightProperty))) { visualTreeNode.Properties[index] = keyValuePair.Value.Clone(documentContext); } } if (documentCompositeNode1.SupportsChildren) { foreach (DocumentNode documentNode in (IEnumerable <DocumentNode>)documentCompositeNode1.Children) { visualTreeNode.Children.Add(documentNode.Clone(documentContext)); } } if (!PlatformTypes.Panel.IsAssignableFrom((ITypeId)documentCompositeNode1.Type)) { GridElement gridElement = (GridElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Grid); SceneNode sceneNode = this.SceneViewModel.GetSceneNode((DocumentNode)visualTreeNode); gridElement.Children.Add(sceneNode); visualTreeNode = (DocumentCompositeNode)gridElement.DocumentNode; } StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Style); styleNode.StyleTargetTypeId = type3; SetterSceneNode setterSceneNode = (SetterSceneNode)this.SceneViewModel.CreateSceneNode(PlatformTypes.Setter); DependencyPropertyReferenceStep propertyReferenceStep1 = (DependencyPropertyReferenceStep)this.SceneViewModel.ProjectContext.ResolveProperty(ControlElement.TemplateProperty); setterSceneNode.Property = propertyReferenceStep1; BaseFrameworkElement frameworkElement = (BaseFrameworkElement)this.SceneViewModel.CreateSceneNode(type2); DocumentCompositeNode documentCompositeNode2 = (DocumentCompositeNode)frameworkElement.DocumentNode; this.AddPresenterIfNecessary(visualTreeNode, (SceneElement)frameworkElement); ControlTemplateElement controlTemplateElement = (ControlTemplateElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.ControlTemplate); controlTemplateElement.ControlTemplateTargetTypeId = (ITypeId)type3; controlTemplateElement.DefaultInsertionPoint.Insert(this.SceneViewModel.GetSceneNode((DocumentNode)visualTreeNode)); if (PlatformTypes.Button.Equals((object)type3) && controlTemplateElement.CanEditTriggers && this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf)) { DocumentCompositeNode node = documentContext.CreateNode(typeof(TriggerCollection)); node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsFocusedProperty, (object)true)); node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsDefaultedProperty, (object)true)); node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, BaseFrameworkElement.IsMouseOverProperty, (object)true)); node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, ButtonProperties.IsPressedProperty, (object)true)); node.Children.Add((DocumentNode)this.CreatePropertyTrigger(documentContext, BaseFrameworkElement.IsEnabledProperty, (object)false)); controlTemplateElement.SetLocalValue(ControlTemplateElement.ControlTemplateTriggersProperty, (DocumentNode)node); } setterSceneNode.SetValueAsSceneNode(SetterSceneNode.ValueProperty, (SceneNode)controlTemplateElement); styleNode.Setters.Add((SceneNode)setterSceneNode); bool useStaticResource = !JoltHelper.TypeSupported((ITypeResolver)this.SceneViewModel.ProjectContext, PlatformTypes.DynamicResource); int index1 = -1; if (useStaticResource && selectedElement.DocumentContext == createResourceModel.CurrentResourceSite.DocumentContext) { index1 = createResourceModel.IndexInResourceSite(selectedElement.DocumentNode); } IList <DocumentCompositeNode> referencedResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources((DocumentNode)documentCompositeNode1); foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in dictionary) { documentCompositeNode2.Properties[(IPropertyId)keyValuePair.Key] = keyValuePair.Value; } IList <SceneNode> nodes = (IList <SceneNode>) new List <SceneNode>(); nodes.Add((SceneNode)frameworkElement); SceneNode parent = selectedElement.Parent; IProperty propertyForChild = parent.GetPropertyForChild((SceneNode)selectedElement); ISceneNodeCollection <SceneNode> collectionForProperty = parent.GetCollectionForProperty((IPropertyId)propertyForChild); int index2 = collectionForProperty.IndexOf((SceneNode)selectedElement); collectionForProperty[index2] = (SceneNode)frameworkElement; if (createResourceModel.SelectedResourceDictionary != null) { ResourceContainer instance = createResourceModel.SelectedResourceDictionary.Instance; if (instance != null && instance.DocumentNode == documentCompositeNode1) { createResourceModel = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, type1.RuntimeType, type2, PlatformTypes.Style.Name, (SceneElement)frameworkElement, (SceneNode)null, contextFlags); } } if (createResourceModel.CurrentResourceSite != null && !PlatformTypes.PlatformsCompatible(createResourceModel.CurrentResourceSite.DocumentContext.TypeResolver.PlatformMetadata, styleNode.DocumentNode.PlatformMetadata)) { editTransaction1.Cancel(); return; } DocumentCompositeNode resource = createResourceModel.CreateResource(styleNode.DocumentNode, StyleNode.TargetTypeProperty, index1); if (resource == null) { editTransaction1.Cancel(); return; } DocumentNode resourceReference = createResourceModel.CreateResourceReference(this.SceneViewModel.Document.DocumentContext, resource, useStaticResource); DefaultTypeInstantiator typeInstantiator = new DefaultTypeInstantiator(this.SceneView); if (resourceReference != null) { documentCompositeNode2.Properties[BaseFrameworkElement.StyleProperty] = resourceReference; } foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode1.Properties) { IPropertyId index3 = (IPropertyId)keyValuePair.Key; DependencyPropertyReferenceStep propertyReferenceStep2 = index3 as DependencyPropertyReferenceStep; if (propertyReferenceStep2 != null && propertyReferenceStep2.IsAttachable && propertyReferenceStep2.MemberType != MemberType.DesignTimeProperty) { documentCompositeNode2.Properties[index3] = keyValuePair.Value.Clone(documentContext); } } DocumentCompositeNode hostNode = createResourceModel.CurrentResourceSite.HostNode; SceneViewModel viewModel = this.SceneViewModel.GetViewModel(hostNode.DocumentRoot, false); using (SceneEditTransaction editTransaction2 = viewModel.CreateEditTransaction(this.UndoString)) { Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CopyResourcesToNewResourceSite(referencedResources, viewModel, hostNode, resource, createResourceModel.IndexInResourceSite((DocumentNode)resource)); editTransaction2.Commit(); } editTransaction1.Update(); if (this.SceneView.IsValid) { typeInstantiator.ApplyAfterInsertionDefaultsToElements(nodes, (SceneNode)null); } this.SceneView.CandidateEditingContainer = frameworkElement.DocumentNodePath; editTransaction1.Update(); this.SceneViewModel.ElementSelectionSet.ExtendSelection((SceneElement)frameworkElement); this.PostProcessing((SceneNode)selectedElement, (SceneNode)frameworkElement, resource); if (frameworkElement.GetComputedValue(ControlElement.TemplateProperty) != null) { this.ActivateTemplateEditingMode((SceneElement)frameworkElement); } else { UIThreadDispatcherHelper.BeginInvoke(DispatcherPriority.ApplicationIdle, (Delegate) new Action <SceneElement>(this.ActivateTemplateEditingMode), (object)frameworkElement); } this.SceneView.CandidateEditingContainer = (DocumentNodePath)null; } editTransaction1.Commit(); } } } }