Beispiel #1
0
 public static DocumentCompositeNode FindResource(DocumentNode key, DocumentCompositeNode resourcesCollection, int numberOfChildrenToSearch)
 {
     if (resourcesCollection != null && resourcesCollection.SupportsChildren)
     {
         IList <DocumentNode> children = resourcesCollection.Children;
         if (numberOfChildrenToSearch < 0)
         {
             numberOfChildrenToSearch = children.Count;
         }
         for (int i = 0; i < numberOfChildrenToSearch; i++)
         {
             DocumentCompositeNode item = children[i] as DocumentCompositeNode;
             if (item != null)
             {
                 DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(item);
                 if (resourceEntryKey == null)
                 {
                     DocumentCompositeNode documentCompositeNode = item.Properties[KnownProperties.DictionaryEntryValueProperty] as DocumentCompositeNode;
                     if (documentCompositeNode != null)
                     {
                         resourceEntryKey = ResourceSite.GetImplicitKey(documentCompositeNode);
                     }
                 }
                 if (resourceEntryKey != null && resourceEntryKey.Equals(key))
                 {
                     return(item);
                 }
             }
         }
     }
     return(null);
 }
Beispiel #2
0
        public static bool CompareTriggerNodes(DocumentCompositeNode triggerNode1, DocumentCompositeNode triggerNode2)
        {
            IProperty propertyKey = triggerNode1.TypeResolver.ResolveProperty(BehaviorTriggerBaseNode.BehaviorActionsProperty);
            bool      flag        = false;
            int       num1        = 0;

            if (triggerNode1.Properties.Count <= triggerNode2.Properties.Count)
            {
                flag = true;
                foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)triggerNode2.Properties)
                {
                    IProperty    key          = keyValuePair.Key;
                    DocumentNode documentNode = triggerNode1.Properties[(IPropertyId)key];
                    if (!key.Equals((object)propertyKey))
                    {
                        if (documentNode == null || !documentNode.Equals(keyValuePair.Value))
                        {
                            flag = false;
                            break;
                        }
                        ++num1;
                    }
                }
            }
            if (!flag)
            {
                return(false);
            }
            int num2 = triggerNode1.Properties.Contains(propertyKey) ? triggerNode1.Properties.Count - 1 : triggerNode1.Properties.Count;

            return(num1 == num2);
        }
        private static void ReplaceTemplateTargetType(DocumentNode root, IList <DocumentCompositeNode> resources, IType targetType)
        {
            DocumentCompositeNode node = root as DocumentCompositeNode;

            if (node == null)
            {
                return;
            }
            DocumentCompositeNode parent = root.Parent;

            if (parent != null && PlatformTypes.Setter.IsAssignableFrom((ITypeId)parent.Type) && (parent.TypeResolver.ResolveProperty(SetterSceneNode.TargetNameProperty) == null || parent.Properties[SetterSceneNode.TargetNameProperty] == null) && (ControlStylingOperations.DoesPropertyAffectRoot((IPropertyId)root.GetValueProperty()) && parent.Properties[SetterSceneNode.ValueProperty] == root))
            {
                if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)root.Type))
                {
                    node.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)node.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType));
                }
                else if (DocumentNodeUtilities.IsDynamicResource(root) || DocumentNodeUtilities.IsStaticResource(root))
                {
                    DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                    if (resourceKey != null && resources != null)
                    {
                        foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)resources)
                        {
                            if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                            {
                                DocumentCompositeNode documentCompositeNode = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                if (documentCompositeNode != null)
                                {
                                    if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                                    {
                                        documentCompositeNode.Properties[ControlTemplateElement.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType));
                                        break;
                                    }
                                    break;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (parent != null && DocumentNodeUtilities.IsStyleOrTemplate(root.Type))
            {
                return;
            }
            foreach (DocumentNode root1 in node.ChildNodes)
            {
                ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(root1, resources, targetType);
            }
        }
Beispiel #4
0
 private static void ChangeKey(IList <SceneNode> elements, DictionaryEntryNode resource, DocumentNode oldKey, DocumentNode newKey)
 {
     resource.KeyNode = resource.ViewModel.GetSceneNode(newKey);
     if (elements == null)
     {
         return;
     }
     foreach (SceneNode sceneNode in (IEnumerable <SceneNode>)elements)
     {
         foreach (DocumentNode expression in sceneNode.DocumentNode.SelectDescendantNodes(new Predicate <DocumentNode>(ResourceHelper.FilterResources)))
         {
             DocumentCompositeNode node = expression as DocumentCompositeNode;
             if (node != null)
             {
                 DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                 if (resourceKey != null && resourceKey.Equals(oldKey) && new ExpressionEvaluator((IDocumentRootResolver)null).EvaluateExpression(sceneNode.DocumentNodePath, expression) == null)
                 {
                     ResourceNodeHelper.SetResourceKey(node, newKey.Clone(sceneNode.DocumentContext));
                 }
             }
         }
     }
 }
Beispiel #5
0
        public override DocumentNode GetLocalValueAsDocumentNode(SceneNodeProperty property, GetLocalValueFlags flags, out bool isMixed)
        {
            DocumentNode documentNode = (DocumentNode)null;
            bool         flag         = false;

            foreach (SceneNode sceneNode1 in this.Objects)
            {
                PropertyReference propertyReference1 = SceneNodeObjectSet.FilterProperty(sceneNode1, property.Reference);
                if (propertyReference1 != null)
                {
                    DocumentNode other = (DocumentNode)null;
                    if ((flags & GetLocalValueFlags.CheckKeyframes) != GetLocalValueFlags.None && sceneNode1.ViewModel.AnimationEditor.ActiveStoryboardTimeline != null && this.ShouldAllowAnimation)
                    {
                        SceneNode         ancestor           = (SceneNode)null;
                        PropertyReference propertyReference2 = propertyReference1;
                        SceneNode         sceneNode2         = sceneNode1;
                        if (this.FindAncestor(sceneNode1, out ancestor, ref propertyReference2, new Predicate <SceneNode>(SceneNodeObjectSetBase.IsAnimationParent)))
                        {
                            sceneNode2 = ancestor;
                        }
                        foreach (TimelineSceneNode timelineSceneNode in (IEnumerable <TimelineSceneNode>)sceneNode1.ViewModel.AnimationEditor.ActiveStoryboardTimeline.Children)
                        {
                            TimelineSceneNode.PropertyNodePair elementAndProperty = timelineSceneNode.TargetElementAndProperty;
                            if (elementAndProperty.SceneNode == sceneNode2 && elementAndProperty.PropertyReference != null)
                            {
                                PropertyReference propertyReference3 = SceneNodeObjectSet.FilterProperty(elementAndProperty.SceneNode, elementAndProperty.PropertyReference);
                                if (propertyReference2.Equals((object)propertyReference3))
                                {
                                    KeyFrameAnimationSceneNode animationSceneNode1 = timelineSceneNode as KeyFrameAnimationSceneNode;
                                    FromToAnimationSceneNode   animationSceneNode2 = timelineSceneNode as FromToAnimationSceneNode;
                                    if (animationSceneNode1 != null)
                                    {
                                        KeyFrameSceneNode keyFrameAtTime = animationSceneNode1.GetKeyFrameAtTime(sceneNode1.ViewModel.AnimationEditor.AnimationTime);
                                        if (keyFrameAtTime != null)
                                        {
                                            using ((flags & GetLocalValueFlags.Resolve) == GetLocalValueFlags.None ? this.ViewModel.ForceBaseValue() : (IDisposable)null)
                                            {
                                                other = keyFrameAtTime.ValueNode;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    else if (animationSceneNode2 != null)
                                    {
                                        double animationTime = sceneNode1.ViewModel.AnimationEditor.AnimationTime;
                                        using ((flags & GetLocalValueFlags.Resolve) == GetLocalValueFlags.None ? this.ViewModel.ForceBaseValue() : (IDisposable)null)
                                        {
                                            DocumentNodePath documentNodePath = (DocumentNodePath)null;
                                            if (animationTime == animationSceneNode2.Begin + animationSceneNode2.Duration)
                                            {
                                                documentNodePath = animationSceneNode2.GetLocalValueAsDocumentNode(animationSceneNode2.ToProperty);
                                            }
                                            else if (animationTime == animationSceneNode2.Begin)
                                            {
                                                documentNodePath = animationSceneNode2.GetLocalValueAsDocumentNode(animationSceneNode2.FromProperty);
                                            }
                                            other = documentNodePath != null ? documentNodePath.Node : (DocumentNode)null;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (other == null)
                    {
                        if ((flags & GetLocalValueFlags.Resolve) != GetLocalValueFlags.None)
                        {
                            DocumentNodePath valueAsDocumentNode = sceneNode1.GetLocalValueAsDocumentNode(propertyReference1);
                            if (valueAsDocumentNode != null)
                            {
                                other = valueAsDocumentNode.Node;
                            }
                        }
                        else
                        {
                            other = (DocumentNode)sceneNode1.GetLocalValue(propertyReference1, PropertyContext.AsDocumentNodes);
                        }
                    }
                    if (!flag)
                    {
                        if (other == null && (flags & GetLocalValueFlags.SkipCheckIfMixed) != GetLocalValueFlags.None)
                        {
                            isMixed = false;
                            return((DocumentNode)null);
                        }
                        flag         = true;
                        documentNode = other;
                    }
                    else if (documentNode == null && other != null || documentNode != null && !documentNode.Equals(other))
                    {
                        isMixed = true;
                        return((DocumentNode)null);
                    }
                }
            }
            isMixed = false;
            return(documentNode);
        }
        protected DocumentNode ProvideCurrentStyle(SceneElement targetElement, IType targetType, PropertyReference targetPropertyReference, bool allowDefaultStyle, out IList <DocumentCompositeNode> auxillaryResources)
        {
            auxillaryResources = (IList <DocumentCompositeNode>)null;
            DocumentNode currentStyle = (DocumentNode)null;
            bool         isThemeStyle = false;
            IType        targetType1  = targetType;

            if (!this.TargetProperty.Equals((object)BaseFrameworkElement.StyleProperty))
            {
                IDocumentContext documentContext    = this.SceneViewModel.Document.DocumentContext;
                Type             propertyTargetType = this.SceneViewModel.Document.ProjectContext.MetadataFactory.GetMetadata(this.Type.RuntimeType).GetStylePropertyTargetType((IPropertyId)this.TargetProperty);
                targetType1 = propertyTargetType == (Type)null ? (IType)null : this.SceneViewModel.ProjectContext.GetType(propertyTargetType);
            }
            if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                DocumentNodePath valueAsDocumentNode = targetElement.GetLocalValueAsDocumentNode(targetPropertyReference);
                if (valueAsDocumentNode != null && valueAsDocumentNode.Node is DocumentCompositeNode && PlatformTypes.Style.IsAssignableFrom((ITypeId)valueAsDocumentNode.Node.Type) && (!StyleNode.IsDefaultValue(valueAsDocumentNode.Node) || allowDefaultStyle))
                {
                    StyleNode styleNode = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as StyleNode;
                    if (styleNode != null)
                    {
                        currentStyle       = styleNode.DocumentNode;
                        auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(valueAsDocumentNode.Node);
                    }
                }
            }
            if (currentStyle == null)
            {
                object obj = this.ResolveCurrentStyle(targetElement, targetPropertyReference, allowDefaultStyle);
                if (obj != null)
                {
                    DocumentNode correspondingDocumentNode = this.SceneView.GetCorrespondingDocumentNode(this.SceneViewModel.ProjectContext.Platform.ViewObjectFactory.Instantiate(obj), true);
                    if (correspondingDocumentNode != null && PlatformTypes.Style.IsAssignableFrom((ITypeId)correspondingDocumentNode.Type))
                    {
                        currentStyle = correspondingDocumentNode;
                    }
                    else if (obj is Style)
                    {
                        StyleNode styleNode = (StyleNode)this.SceneViewModel.CreateSceneNode(obj);
                        if (targetType1 != null)
                        {
                            styleNode.StyleTargetTypeId = targetType1;
                        }
                        currentStyle = styleNode.DocumentNode;
                    }
                }
                if (currentStyle != null && !allowDefaultStyle && StyleNode.IsDefaultValue(currentStyle))
                {
                    currentStyle = (DocumentNode)null;
                }
            }
            if (currentStyle == null)
            {
                object defaultStyleKey = this.GetDefaultStyleKey(targetElement, (ITypeId)targetType1, (IPropertyId)this.TargetProperty);
                if (defaultStyleKey != null)
                {
                    this.ResolveDefaultStyle(targetElement, defaultStyleKey, allowDefaultStyle, out currentStyle, out isThemeStyle, out auxillaryResources);
                }
            }
            if (currentStyle != null && !allowDefaultStyle)
            {
                List <DocumentCompositeNode> list = new List <DocumentCompositeNode>();
                DocumentCompositeNode        node = currentStyle as DocumentCompositeNode;
                IProperty property = this.SceneViewModel.ProjectContext.ResolveProperty(StyleNode.BasedOnProperty);
                while (node != null && property != null && (node.Type.Equals((object)PlatformTypes.Style) && node.Properties.Count == 2) && (node.Properties[(IPropertyId)property] != null && node.Properties[StyleNode.TargetTypeProperty] != null))
                {
                    node = node.Properties[StyleNode.BasedOnProperty] as DocumentCompositeNode;
                    if (node != null)
                    {
                        if (DocumentNodeUtilities.IsDynamicResource((DocumentNode)node) || DocumentNodeUtilities.IsStaticResource((DocumentNode)node))
                        {
                            DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(node);
                            if (resourceKey != null && auxillaryResources != null)
                            {
                                foreach (DocumentCompositeNode entryNode in (IEnumerable <DocumentCompositeNode>)auxillaryResources)
                                {
                                    if (resourceKey.Equals(ResourceNodeHelper.GetResourceEntryKey(entryNode)))
                                    {
                                        node = entryNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
                                        break;
                                    }
                                }
                            }
                        }
                        if (PlatformTypes.Style.IsAssignableFrom((ITypeId)node.Type))
                        {
                            currentStyle = (DocumentNode)node;
                            list.Add(node);
                        }
                    }
                }
                if (auxillaryResources != null)
                {
                    foreach (DocumentNode documentNode in list)
                    {
                        DocumentCompositeNode parent = documentNode.Parent;
                        if (parent != null && parent.Type.Equals((object)PlatformTypes.DictionaryEntry))
                        {
                            auxillaryResources.Remove(parent);
                        }
                    }
                }
                if (currentStyle != null && (list.Count > 0 || currentStyle.DocumentRoot != null))
                {
                    currentStyle = currentStyle.Clone(targetElement.DocumentContext);
                }
                if (auxillaryResources != null)
                {
                    for (int index = 0; index < auxillaryResources.Count; ++index)
                    {
                        if (auxillaryResources[index].DocumentRoot != null)
                        {
                            auxillaryResources[index] = (DocumentCompositeNode)auxillaryResources[index].Clone(targetElement.DocumentContext);
                        }
                    }
                }
                if (isThemeStyle)
                {
                    ReplaceStyleTemplateCommand.StripFormatting(currentStyle);
                    if (auxillaryResources != null)
                    {
                        for (int index = 0; index < auxillaryResources.Count; ++index)
                        {
                            ReplaceStyleTemplateCommand.StripFormatting((DocumentNode)auxillaryResources[index]);
                        }
                    }
                }
                DocumentCompositeNode documentCompositeNode = currentStyle as DocumentCompositeNode;
                if (documentCompositeNode != null && targetType1 != null)
                {
                    documentCompositeNode.Properties[StyleNode.TargetTypeProperty] = (DocumentNode)documentCompositeNode.Context.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)targetType1));
                }
                if (targetType1 != null)
                {
                    ReplaceStyleTemplateCommand.ReplaceTemplateTargetType(currentStyle, auxillaryResources, targetType1);
                }
            }
            return(currentStyle);
        }