Exemple #1
0
 private void ApplyRelativeTransformToElements(IEnumerable targetElements, PropertyReference reference, IApplyRelativeTransform transformModel)
 {
     foreach (SceneNode sceneNode in targetElements)
     {
         SceneElement sceneElement = sceneNode as SceneElement;
         if (sceneElement != null)
         {
             if (sceneElement is BaseFrameworkElement && sceneElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset)
             {
                 sceneElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5));
             }
             object             computedValueAsWpf = sceneElement.GetComputedValueAsWpf(reference);
             object             obj = transformModel.ApplyRelativeTransform(computedValueAsWpf);
             CanonicalTransform canonicalTransform = obj as CanonicalTransform;
             if (canonicalTransform != (CanonicalTransform)null)
             {
                 sceneElement.SetValue(reference, canonicalTransform.GetPlatformTransform(sceneElement.Platform.GeometryHelper));
             }
             else
             {
                 CanonicalTransform3D canonicalTransform3D = obj as CanonicalTransform3D;
                 if (canonicalTransform3D != (CanonicalTransform3D)null)
                 {
                     sceneElement.SetValue(reference, (object)canonicalTransform3D.ToTransform());
                 }
             }
         }
     }
 }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        private void ApplyPaintBucket(SceneElement hitElement)
        {
            this.EnsureEditTransaction();
            PropertyManager   propertyManager  = (PropertyManager)this.ToolBehaviorContext.PropertyManager;
            IPlatform         platform         = this.ActiveDocument.ProjectContext.Platform;
            IPlatformMetadata platformMetadata = (IPlatformMetadata)platform.Metadata;

            foreach (IPropertyId propertyId in PropertyToolBehavior.PropertyList)
            {
                ReferenceStep singleStep = platformMetadata.ResolveProperty(propertyId) as ReferenceStep;
                if (singleStep != null && singleStep.PropertyType.PlatformMetadata == platform.Metadata)
                {
                    PropertyReference propertyReference1 = new PropertyReference(singleStep);
                    PropertyReference propertyReference2 = propertyManager.FilterProperty((SceneNode)hitElement, propertyReference1);
                    if (propertyReference2 != null)
                    {
                        object obj           = propertyManager.GetValue(propertyReference2);
                        object computedValue = hitElement.GetComputedValue(propertyReference2);
                        if (obj != MixedProperty.Mixed && !PropertyUtilities.Compare(computedValue, obj, hitElement.ViewModel.DefaultView))
                        {
                            hitElement.SetValue(propertyReference2, obj);
                        }
                    }
                }
            }
            this.UpdateEditTransaction();
        }
Exemple #4
0
        private void ApplyResourceOnExistingElement(SceneElement targetElement, IPropertyId targetProperty, ResourceEntryItem resource)
        {
            if (resource.Resource.KeyNode != null || targetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
            {
                using (SceneEditTransaction editTransaction = this.ActiveDocument.CreateEditTransaction(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertySetUndo, new object[1]
                {
                    (object)targetProperty.Name
                })))
                {
                    if (resource.Resource.KeyNode != null)
                    {
                        IDocumentContext documentContext = this.ActiveSceneViewModel.Document.DocumentContext;
                        IProjectContext  projectContext  = this.ActiveSceneViewModel.Document.ProjectContext;
                        DocumentNode     keyNode         = resource.Resource.KeyNode.Clone(documentContext);
                        DocumentNode     documentNode    = !(projectContext.ResolveProperty(targetProperty) is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.DynamicResource) ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
                        targetElement.SetValue(targetProperty, (object)documentNode);
                    }
                    else if (targetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
                    {
                        targetElement.ClearValue(targetProperty);
                    }
                    editTransaction.Commit();
                }
            }
            ResourceManager   resourceManager   = this.ActiveSceneViewModel.DesignerContext.ResourceManager;
            DocumentReference documentReference = resource.Container.DocumentReference;

            if (resource.Resource.IsResourceReachable((SceneNode)targetElement) || !(documentReference != resourceManager.ActiveRootContainer.DocumentReference) || !(documentReference != resourceManager.TopLevelResourceContainer.DocumentReference))
            {
                return;
            }
            resourceManager.LinkToResource(resourceManager.TopLevelResourceContainer, documentReference);
        }
Exemple #5
0
 public static void SetLayoutOverrides(SceneElement element, LayoutOverrides flags)
 {
     if (flags == LayoutOverrides.None)
     {
         element.ClearValue(DesignTimeProperties.LayoutOverridesProperty);
     }
     else
     {
         element.SetValue(DesignTimeProperties.LayoutOverridesProperty, (object)flags);
     }
 }
 private static void SetAutoLayoutRounding(SceneElement element, bool auto)
 {
     if (auto)
     {
         element.SetValue(DesignTimeProperties.LayoutRoundingProperty, (object)LayoutRoundingHelper.AutoLayoutRoundingValue);
     }
     else
     {
         element.ClearValue(DesignTimeProperties.LayoutRoundingProperty);
     }
 }
 private static void ForceClearPropertyInspector(IPropertyId resolvedProperty, SceneElement element)
 {
     using (element.ViewModel.ForceBaseValue())
     {
         SceneEditTransaction editTransaction = element.DesignerContext.ActiveDocument.CreateEditTransaction("Hidden", true);
         using (editTransaction)
         {
             element.SetValue(resolvedProperty, (object)true);
             editTransaction.Cancel();
         }
     }
 }
Exemple #8
0
        private void CreateInstance(Point dropPoint, ResourceEntryItem resource, IType type)
        {
            ISceneInsertionPoint pointFromPosition = this.ActiveSceneViewModel.GetActiveSceneInsertionPointFromPosition(new InsertionPointContext(dropPoint));
            TypeAsset            typeAsset         = new TypeAsset(type);

            if (!typeAsset.CanCreateInstance(pointFromPosition))
            {
                return;
            }
            this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, (BaseFrameworkElement)null, (IList <BaseFrameworkElement>)null);
            dropPoint = this.ToolBehaviorContext.SnappingEngine.SnapPoint(dropPoint, EdgeFlags.All);
            this.ToolBehaviorContext.SnappingEngine.Stop();
            Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(this.ActiveView.GetComputedTransformToRoot(pointFromPosition.SceneElement));

            dropPoint *= inverseMatrix;
            using (SceneEditTransaction editTransaction = this.ActiveDocument.CreateEditTransaction(StringTable.CreateResourceViaToolUndoUnit))
            {
                using (this.ActiveSceneViewModel.DesignerContext.AmbientPropertyManager.SuppressApplyAmbientProperties())
                {
                    typeAsset.CreateInstance(this.ActiveSceneViewModel.DesignerContext.LicenseManager, pointFromPosition, new Rect(dropPoint, new Size(double.PositiveInfinity, double.PositiveInfinity)), (OnCreateInstanceAction)(sceneNode =>
                    {
                        SceneElement targetElement = sceneNode as SceneElement;
                        if (targetElement == null)
                        {
                            return;
                        }
                        if (resource is StyleResourceItem)
                        {
                            this.ApplyResourceOnExistingElement(targetElement, BaseFrameworkElement.StyleProperty, resource);
                        }
                        else if (resource is ControlTemplateResourceItem)
                        {
                            this.ApplyResourceOnExistingElement(targetElement, ControlElement.TemplateProperty, resource);
                        }
                        else if (resource is DrawingImageResourceItem)
                        {
                            this.ApplyResourceOnExistingElement(targetElement, ImageElement.SourceProperty, resource);
                        }
                        else
                        {
                            if (!(resource is BrushResourceItem))
                            {
                                return;
                            }
                            this.ApplyResourceOnExistingElement(targetElement, ShapeElement.FillProperty, resource);
                            targetElement.SetValue(ShapeElement.StrokeProperty, (object)null);
                        }
                    }));
                    editTransaction.Commit();
                }
            }
        }
Exemple #9
0
 private static void SetAnnotationReferences(SceneElement element, IEnumerable <string> ids)
 {
     ExceptionChecks.CheckNullArgument <SceneElement>(element, "element");
     ExceptionChecks.CheckNullArgument <IEnumerable <string> >(ids, "ids");
     if (!Enumerable.Any <string>(ids))
     {
         element.ClearValue(AnnotationSceneNode.ReferencesProperty);
     }
     else
     {
         element.SetValue(AnnotationSceneNode.ReferencesProperty, (object)string.Join(", ", Enumerable.ToArray <string>(ids)));
     }
 }
Exemple #10
0
        protected static void UpdateElementTransform(SceneElement element, CanonicalDecomposition newTransform, AdornedToolBehavior.TransformPropertyFlags properties)
        {
            Transform transform = element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty) as Transform;
            CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition();

            if (transform != null)
            {
                canonicalDecomposition = new CanonicalTransform(transform).Decomposition;
            }
            double num1 = RoundingHelper.RoundScale(newTransform.ScaleX);
            double num2 = RoundingHelper.RoundScale(newTransform.ScaleY);
            double num3 = RoundingHelper.RoundLength(newTransform.TranslationX);
            double num4 = RoundingHelper.RoundLength(newTransform.TranslationY);
            double num5 = RoundingHelper.RoundLength(newTransform.SkewX);
            double num6 = RoundingHelper.RoundLength(newTransform.SkewY);
            double num7 = RoundingHelper.RoundAngle(newTransform.RotationAngle);

            if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleX, num1))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleX, (object)num1);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleY, num2))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleY, (object)num2);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationX, num3))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num3);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationY, num4))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num4);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewX, num5))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewX, (object)num5);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewY, num6))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewY, (object)num6);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.RotatationAngle) == AdornedToolBehavior.TransformPropertyFlags.None || Tolerances.AreClose(canonicalDecomposition.RotationAngle, num7))
            {
                return;
            }
            element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformRotationAngle, (object)num7);
        }
Exemple #11
0
        internal static SceneElement ApplyChildren(SceneElement destinationElement, Dictionary <IPropertyId, List <SceneNode> > storedChildren, Size size)
        {
            SceneElement sceneElement = (SceneElement)null;

            foreach (KeyValuePair <IPropertyId, List <SceneNode> > keyValuePair in storedChildren)
            {
                IPropertyId   childProperty = keyValuePair.Key;
                ReferenceStep referenceStep = childProperty as ReferenceStep;
                if (referenceStep != null)
                {
                    childProperty = (IPropertyId)SceneNodeObjectSet.FilterProperty((SceneNode)destinationElement, referenceStep) ?? (IPropertyId)destinationElement.DefaultContentProperty;
                }
                if (childProperty != null)
                {
                    ISceneNodeCollection <SceneNode> collectionForProperty = destinationElement.GetCollectionForProperty(childProperty);
                    if (collectionForProperty != null)
                    {
                        sceneElement = destinationElement;
                        List <SceneNode> list = keyValuePair.Value;
                        if (collectionForProperty.FixedCapacity.HasValue && list.Count > collectionForProperty.FixedCapacity.Value - collectionForProperty.Count)
                        {
                            SceneNode sceneNode = destinationElement.ViewModel.CreateSceneNode(PlatformTypes.Grid);
                            if (ProjectNeutralTypes.Viewbox.IsAssignableFrom((ITypeId)destinationElement.Type) && !size.IsEmpty)
                            {
                                sceneNode.SetValue(BaseFrameworkElement.WidthProperty, (object)size.Width);
                                sceneNode.SetValue(BaseFrameworkElement.HeightProperty, (object)size.Height);
                            }
                            collectionForProperty.Add(sceneNode);
                            collectionForProperty = sceneNode.GetCollectionForProperty((IPropertyId)sceneNode.DefaultContentProperty);
                            sceneElement          = sceneNode as SceneElement;
                        }
                        if (ProjectNeutralTypes.Viewbox.IsAssignableFrom((ITypeId)destinationElement.Type))
                        {
                            destinationElement.SetValue(ViewboxElement.StretchProperty, (object)Stretch.Fill);
                        }
                        foreach (SceneNode sceneNode in list)
                        {
                            collectionForProperty.Add(sceneNode);
                        }
                    }
                }
            }
            return(sceneElement);
        }
        public static bool UpdateLayoutRounding(SceneElement element)
        {
            if (!LayoutRoundingHelper.ShouldConsiderLayoutRoundingAdjustment(element))
            {
                return(false);
            }
            IPropertyId propertyKey = (IPropertyId)LayoutRoundingHelper.ResolveUseLayoutRoundingProperty((SceneNode)element);

            if (propertyKey == null)
            {
                return(false);
            }
            bool flag1 = element.IsSet(propertyKey) == PropertyState.Set;

            if (PlatformTypes.Path.IsAssignableFrom((ITypeId)element.Type))
            {
                if (!flag1 && (bool)element.GetComputedValue(propertyKey))
                {
                    element.SetLocalValue(Base2DElement.UseLayoutRoundingProperty, (object)false);
                    LayoutRoundingHelper.SetAutoLayoutRounding(element, false);
                    return(true);
                }
            }
            else if (!flag1 || LayoutRoundingHelper.GetAutoLayoutRounding(element))
            {
                bool flag2 = (bool)element.GetComputedValue(propertyKey);
                if (LayoutRoundingHelper.IsAxisAligned(element))
                {
                    if (!flag2)
                    {
                        element.ClearValue(propertyKey);
                        LayoutRoundingHelper.SetAutoLayoutRounding(element, false);
                        return(true);
                    }
                }
                else if (flag2)
                {
                    element.SetValue(propertyKey, (object)false);
                    LayoutRoundingHelper.SetAutoLayoutRounding(element, true);
                    return(true);
                }
            }
            return(false);
        }
Exemple #13
0
 public static void SetBottom(SceneElement element, double length)
 {
     element.SetValue(CanvasElement.BottomProperty, (object)length);
 }
        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();
                    }
                }
            }
        }
 public override void Execute()
 {
     PerformanceUtility.StartPerformanceSequence(PerformanceEvent.EditStyleOrTemplate);
     if (this.IsEnabled)
     {
         SceneElement     targetElement                = this.TargetElement;
         IDocumentContext documentContext              = this.SceneViewModel.Document.DocumentContext;
         Type             propertyTargetType           = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty);
         CreateResourceModel.ContextFlags contextFlags = !PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)this.TargetProperty.PropertyType) ? (this.SceneViewModel.ProjectContext.IsCapabilitySet(PlatformCapability.SupportsImplicitStyles) ? CreateResourceModel.ContextFlags.CanApplyAutomatically : CreateResourceModel.ContextFlags.None) : CreateResourceModel.ContextFlags.None;
         CreateResourceModel           model           = new CreateResourceModel(this.SceneViewModel, this.DesignerContext.ResourceManager, PlatformTypeHelper.GetPropertyType((IProperty)this.TargetProperty), propertyTargetType, this.TargetProperty.Name, (SceneElement)null, (SceneNode)(targetElement as BaseFrameworkElement), contextFlags);
         IList <DocumentCompositeNode> auxillaryResources;
         DocumentNode node1 = this.ProvideValue(out auxillaryResources);
         if (node1 != null)
         {
             IPropertyId           targetTypeProperty    = this.GetTargetTypeProperty((ITypeId)this.TargetProperty.PropertyType);
             DocumentCompositeNode documentCompositeNode = node1 as DocumentCompositeNode;
             if (targetTypeProperty != null && documentCompositeNode != null)
             {
                 IType valueAsType = DocumentPrimitiveNode.GetValueAsType(documentCompositeNode.Properties[targetTypeProperty]);
                 if (valueAsType != null && valueAsType.RuntimeType != (Type)null)
                 {
                     model.TargetType = valueAsType.RuntimeType;
                 }
             }
             else
             {
                 model.TargetType = (Type)null;
             }
             ReplaceStyleTemplateCommand.ExtraReferences references = new ReplaceStyleTemplateCommand.ExtraReferences();
             this.CollectExtraReferences(node1, references);
             if (auxillaryResources != null)
             {
                 foreach (DocumentNode node2 in (IEnumerable <DocumentCompositeNode>)auxillaryResources)
                 {
                     this.CollectExtraReferences(node2, references);
                 }
             }
             if (references.UnresolvedTypes.Count > 0)
             {
                 string message = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CopyStyleTemplateTypesNotInDocumentMessage, new object[2]
                 {
                     (object)this.TargetProperty.Name,
                     (object)SceneView.GetUnresolvedTypesList(references.UnresolvedTypes)
                 });
                 if (!this.ShowUI)
                 {
                     return;
                 }
                 this.DesignerContext.MessageDisplayService.ShowError(message);
                 return;
             }
             if (this.ShowUI)
             {
                 bool?nullable = new CreateResourceDialog(this.DesignerContext, model).ShowDialog();
                 if ((!nullable.GetValueOrDefault() ? 1 : (!nullable.HasValue ? true : false)) != 0)
                 {
                     return;
                 }
             }
             bool flag = model.CurrentResourceSite != null;
             if (!flag || targetElement.DocumentNode.DocumentRoot == null)
             {
                 return;
             }
             SceneViewModel viewModel = this.SceneViewModel.GetViewModel(model.CurrentResourceSite.HostNode.DocumentRoot, false);
             if (viewModel == null || !PlatformTypes.PlatformsCompatible(node1.PlatformMetadata, viewModel.ProjectContext.PlatformMetadata) || !this.AddReferences(viewModel.ProjectContext, references, model.KeyString))
             {
                 return;
             }
             using (SceneEditTransaction editTransaction1 = this.SceneViewModel.CreateEditTransaction(this.UndoString))
             {
                 DocumentNode          documentNode1 = (DocumentNode)null;
                 DocumentCompositeNode resource;
                 using (SceneEditTransaction editTransaction2 = viewModel.CreateEditTransaction(this.UndoString))
                 {
                     DocumentNode newResourceNode;
                     try
                     {
                         newResourceNode = node1.Clone(viewModel.Document.DocumentContext);
                     }
                     catch
                     {
                         editTransaction2.Cancel();
                         editTransaction1.Cancel();
                         this.DesignerContext.MessageDisplayService.ShowError(string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.CommandFailedDialogMessage, new object[1]
                         {
                             (object)this.UndoString
                         }));
                         return;
                     }
                     newResourceNode.Name = (string)null;
                     bool useStaticResource = !(this.TargetProperty is DependencyPropertyReferenceStep) || !JoltHelper.TypeSupported((ITypeResolver)this.SceneViewModel.ProjectContext, PlatformTypes.DynamicResource);
                     int  index             = useStaticResource ? model.IndexInResourceSite(targetElement.DocumentNode) : -1;
                     resource = model.CreateResource(newResourceNode, targetTypeProperty, index);
                     flag     = resource != null;
                     if (flag)
                     {
                         documentNode1 = model.CreateResourceReference(this.SceneViewModel.Document.DocumentContext, resource, useStaticResource);
                         flag          = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.CopyResourcesToNewResourceSite(auxillaryResources, viewModel, model.CurrentResourceSite.HostNode, resource, model.IndexInResourceSite((DocumentNode)resource));
                     }
                     if (flag)
                     {
                         editTransaction2.Commit();
                         if (this.SceneViewModel == viewModel)
                         {
                             editTransaction1.Update();
                             this.DesignerContext.ViewUpdateManager.UpdateRelatedViews(this.SceneViewModel.Document, false);
                         }
                         this.DesignerContext.ViewUpdateManager.RefreshActiveViewApplicationResources();
                     }
                     else
                     {
                         editTransaction2.Cancel();
                     }
                 }
                 if (flag && resource != null)
                 {
                     DocumentNode     documentNode2 = resource.Properties[DictionaryEntryNode.ValueProperty];
                     DocumentNodePath documentNodePath;
                     if (targetElement.IsAttached)
                     {
                         if (documentNode1 != null)
                         {
                             targetElement.SetValue(this.TargetPropertyReference, (object)documentNode1);
                         }
                         else
                         {
                             targetElement.ClearValue(this.TargetPropertyReference);
                         }
                         this.SceneView.CandidateEditingContainer = targetElement.DocumentNodePath;
                         editTransaction1.Update();
                         this.SceneView.CandidateEditingContainer = (DocumentNodePath)null;
                         documentNodePath = this.ProvideEditingContainer(targetElement, this.TargetPropertyReference, documentNode2);
                     }
                     else
                     {
                         documentNodePath = (DocumentNodePath)null;
                     }
                     if (this.SceneView.IsValid)
                     {
                         if (documentNodePath != null && documentNodePath.Node != null && (!DocumentNodeUtilities.IsDynamicResource(documentNodePath.Node) && !DocumentNodeUtilities.IsStaticResource(documentNodePath.Node)))
                         {
                             DocumentNode node2             = documentNodePath.Node;
                             bool         preferInPlaceEdit = ControlStylingOperations.CanEditInPlace(targetElement, this.TargetProperty, documentNodePath);
                             ControlStylingOperations.SetActiveEditingContainer(targetElement, this.TargetProperty, node2, documentNodePath, preferInPlaceEdit, editTransaction1);
                         }
                         else
                         {
                             ControlStylingOperations.SetActiveEditingContainer(targetElement, this.TargetProperty, documentNode2, (DocumentNodePath)null, false, editTransaction1);
                         }
                     }
                     editTransaction1.Commit();
                 }
                 else
                 {
                     editTransaction1.Cancel();
                 }
             }
         }
     }
     PerformanceUtility.EndPerformanceSequence(PerformanceEvent.EditStyleOrTemplate);
 }
Exemple #16
0
        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?();
        }
Exemple #17
0
 public static void SetRight(SceneElement element, double length)
 {
     element.SetValue(CanvasElement.RightProperty, (object)length);
 }