Пример #1
0
        private static DocumentNode GetTemplateNode(SceneNode newElement, DocumentCompositeNode styleNode, out StyleNode styleElement)
        {
            DocumentCompositeNode documentCompositeNode1 = styleNode.Properties[DictionaryEntryNode.ValueProperty] as DocumentCompositeNode;
            SceneViewModel        viewModel = newElement.ViewModel.GetViewModel(documentCompositeNode1.DocumentRoot, false);

            if (viewModel == null)
            {
                styleElement = (StyleNode)null;
                return((DocumentNode)null);
            }
            styleElement = viewModel.GetSceneNode((DocumentNode)documentCompositeNode1) as StyleNode;
            DependencyPropertyReferenceStep propertyReferenceStep = (DependencyPropertyReferenceStep)newElement.ViewModel.ProjectContext.ResolveProperty(ControlElement.TemplateProperty);

            if (documentCompositeNode1 != null)
            {
                DocumentCompositeNode documentCompositeNode2 = documentCompositeNode1.Properties[StyleNode.SettersProperty] as DocumentCompositeNode;
                if (documentCompositeNode2 != null)
                {
                    foreach (DocumentNode documentNode1 in (IEnumerable <DocumentNode>)documentCompositeNode2.Children)
                    {
                        DocumentCompositeNode documentCompositeNode3 = documentNode1 as DocumentCompositeNode;
                        if (documentCompositeNode3 != null)
                        {
                            IMemberId    memberId      = (IMemberId)DocumentPrimitiveNode.GetValueAsMember(documentCompositeNode3.Properties[SetterSceneNode.PropertyProperty]);
                            DocumentNode documentNode2 = documentCompositeNode3.Properties[SetterSceneNode.ValueProperty];
                            if (memberId != null && documentNode2 != null && propertyReferenceStep.Equals((object)memberId))
                            {
                                return(documentNode2);
                            }
                        }
                    }
                }
            }
            return((DocumentNode)null);
        }
Пример #2
0
        private bool IsExplicitAnimationProperty(DocumentNode node)
        {
            DocumentPrimitiveNode documentPrimitiveNode = node as DocumentPrimitiveNode;

            if (documentPrimitiveNode != null && documentPrimitiveNode.Type.Equals(PlatformTypes.DependencyProperty))
            {
                IMember   valueAsMember = DocumentPrimitiveNode.GetValueAsMember(documentPrimitiveNode);
                IProperty property      = node.TypeResolver.ResolveProperty(DesignTimeProperties.ExplicitAnimationProperty);
                if (valueAsMember != null && valueAsMember.DeclaringType.FullName == property.DeclaringType.FullName && valueAsMember.Name == DesignTimeProperties.ExplicitAnimationPropertyName)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void CollectExtraReferences(DocumentNode node, ReplaceStyleTemplateCommand.ExtraReferences references)
        {
            if (node.Parent != null && node.IsProperty)
            {
                ReplaceStyleTemplateCommand.EnsureMember((IMember)node.SitePropertyKey, references);
            }
            ReplaceStyleTemplateCommand.EnsureType(node.Type, references);
            IMember valueAsMember = DocumentPrimitiveNode.GetValueAsMember(node);

            if (valueAsMember != null)
            {
                ReplaceStyleTemplateCommand.EnsureMember(valueAsMember, references);
            }
            foreach (DocumentNode node1 in node.ChildNodes)
            {
                this.CollectExtraReferences(node1, references);
            }
        }
Пример #4
0
        private bool IsSetter(DocumentCompositeNode setterNode, string id, IPropertyId propertyKey)
        {
            bool flag = false;

            if (propertyKey is DependencyPropertyReferenceStep)
            {
                string targetName = this.GetTargetName(setterNode);
                if (id == targetName)
                {
                    DocumentPrimitiveNode documentPrimitiveNode = setterNode.Properties[SetterSceneNode.PropertyProperty] as DocumentPrimitiveNode;
                    if (documentPrimitiveNode == null)
                    {
                        throw new InvalidDataException(ExceptionStringTable.VisualTriggerSetterDoesNotContainPropertyPath);
                    }
                    IMemberId memberId = (IMemberId)DocumentPrimitiveNode.GetValueAsMember((DocumentNode)documentPrimitiveNode);
                    if (memberId != null && memberId == propertyKey)
                    {
                        flag = true;
                    }
                }
            }
            return(flag);
        }
Пример #5
0
 protected virtual bool ShouldSerialize(XamlSerializerContext serializerContext, DocumentNode node)
 {
     if (node.Type != null)
     {
         DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;
         if (documentCompositeNode != null && this.IsExplicitKeyframe(documentCompositeNode))
         {
             return(false);
         }
         if (documentCompositeNode != null && documentCompositeNode.Properties[DesignTimeProperties.ShouldSerializeProperty] != null)
         {
             return(false);
         }
         if (PlatformTypes.Setter.IsAssignableFrom(node.Type) && documentCompositeNode != null)
         {
             DocumentPrimitiveNode item = documentCompositeNode.Properties[KnownProperties.SetterPropertyProperty] as DocumentPrimitiveNode;
             if (item != null)
             {
                 IPropertyId valueAsMember = DocumentPrimitiveNode.GetValueAsMember(item) as IPropertyId;
                 if (valueAsMember != null && valueAsMember.MemberType == MemberType.DesignTimeProperty)
                 {
                     return(false);
                 }
             }
         }
         if (node.Parent != null && node.Parent.Properties[DesignTimeProperties.ShouldSerializeProperty] != null)
         {
             return(false);
         }
         if (!DefaultXamlSerializerFilter.IsTypeSerializable(serializerContext.TypeResolver, node.Type))
         {
             return(false);
         }
     }
     return(true);
 }
        protected DocumentNode ProvideCurrentTemplate(SceneElement targetElement, PropertyReference targetPropertyReference, out IList <DocumentCompositeNode> auxillaryResources)
        {
            IPlatform platform = this.SceneViewModel.ProjectContext.Platform;
            FrameworkTemplateElement frameworkTemplateElement1 = (FrameworkTemplateElement)null;

            auxillaryResources = (IList <DocumentCompositeNode>)null;
            if (targetElement.IsSet(targetPropertyReference) == PropertyState.Set)
            {
                FrameworkTemplateElement frameworkTemplateElement2 = targetElement.GetLocalValueAsSceneNode(targetPropertyReference) as FrameworkTemplateElement;
                if (frameworkTemplateElement2 != null)
                {
                    frameworkTemplateElement1 = targetElement.ClonePropertyValueAsSceneNode(targetPropertyReference) as FrameworkTemplateElement;
                    if (frameworkTemplateElement1 != null)
                    {
                        auxillaryResources = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(frameworkTemplateElement2.DocumentNode);
                    }
                }
            }
            if (frameworkTemplateElement1 == null)
            {
                object                computedValue          = targetElement.GetComputedValue(targetPropertyReference);
                DocumentNode          root                   = computedValue == null ? (DocumentNode)null : this.SceneView.GetCorrespondingDocumentNode(platform.ViewObjectFactory.Instantiate(computedValue), true);
                IPropertyId           targetProperty         = (IPropertyId)targetElement.Platform.Metadata.ResolveProperty(BaseFrameworkElement.StyleProperty);
                DocumentCompositeNode documentCompositeNode1 = targetElement.DocumentNode as DocumentCompositeNode;
                if (!targetElement.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf) && documentCompositeNode1 != null && (root == null && targetPropertyReference.ReferenceSteps.Count == 1))
                {
                    ITypeId       styleTargetType = (ITypeId)targetElement.Type;
                    DocumentNode  currentStyle    = (DocumentNode)null;
                    ReferenceStep referenceStep   = targetPropertyReference.ReferenceSteps[0];
                    object        defaultStyleKey = this.GetDefaultStyleKey(targetElement, styleTargetType, targetProperty);
                    if (defaultStyleKey != null)
                    {
                        bool isThemeStyle;
                        IList <DocumentCompositeNode> auxillaryResources1;
                        this.ResolveDefaultStyle(targetElement, defaultStyleKey, true, out currentStyle, out isThemeStyle, out auxillaryResources1);
                    }
                    DocumentCompositeNode documentCompositeNode2 = currentStyle as DocumentCompositeNode;
                    if (documentCompositeNode2 != null)
                    {
                        DocumentCompositeNode documentCompositeNode3 = documentCompositeNode2.Properties[StyleNode.SettersProperty] as DocumentCompositeNode;
                        if (documentCompositeNode3 != null)
                        {
                            foreach (DocumentNode documentNode1 in (IEnumerable <DocumentNode>)documentCompositeNode3.Children)
                            {
                                DocumentCompositeNode documentCompositeNode4 = documentNode1 as DocumentCompositeNode;
                                if (documentCompositeNode4 != null)
                                {
                                    IMemberId    memberId      = (IMemberId)DocumentPrimitiveNode.GetValueAsMember(documentCompositeNode4.Properties[SetterSceneNode.PropertyProperty]);
                                    DocumentNode documentNode2 = documentCompositeNode4.Properties[SetterSceneNode.ValueProperty];
                                    if (memberId != null && documentNode2 != null && referenceStep.Equals((object)memberId))
                                    {
                                        root = documentNode2;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (root != null)
                {
                    frameworkTemplateElement1 = this.SceneViewModel.GetSceneNode(root.Clone(this.SceneViewModel.Document.DocumentContext)) as FrameworkTemplateElement;
                    auxillaryResources        = Microsoft.Expression.DesignSurface.Utility.ResourceHelper.FindReferencedResources(root);
                }
                else
                {
                    frameworkTemplateElement1 = this.SceneViewModel.CreateSceneNode(computedValue) as FrameworkTemplateElement;
                }
            }
            if (frameworkTemplateElement1 == null)
            {
                return((DocumentNode)null);
            }
            return(frameworkTemplateElement1.DocumentNode);
        }
Пример #7
0
        private DocumentNode ConvertSubtree(DocumentNode node, IDocumentContext sourcePlatformDocumentContext, IDocumentContext targetPlatformDocumentContext)
        {
            DocumentPrimitiveNode documentPrimitiveNode = node as DocumentPrimitiveNode;
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentPrimitiveNode != null)
            {
                ITypeId typeId        = (ITypeId)PlatformTypeHelper.ConvertTypeId((ITypeId)documentPrimitiveNode.Type, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                object  valueAsObject = DocumentPrimitiveNode.GetValueAsObject((DocumentNode)documentPrimitiveNode);
                if (valueAsObject != null)
                {
                    return((DocumentNode) new DocumentPrimitiveNode(targetPlatformDocumentContext, typeId, this.ConvertInternal(valueAsObject, sourcePlatformDocumentContext, targetPlatformDocumentContext, PlatformConverter.ConvertToType.InstanceValue)));
                }
                IDocumentNodeValue documentNodeValue = DocumentPrimitiveNode.GetValueAsMember((DocumentNode)documentPrimitiveNode) != null || documentPrimitiveNode.Value == null ? (IDocumentNodeValue)null : documentPrimitiveNode.Value.Clone(targetPlatformDocumentContext);
                return((DocumentNode) new DocumentPrimitiveNode(targetPlatformDocumentContext, typeId, documentNodeValue));
            }
            if (documentCompositeNode != null)
            {
                if (PlatformTypes.CompositeTransform.IsAssignableFrom((ITypeId)documentCompositeNode.Type))
                {
                    IPlatform platform = PlatformConverter.GetPlatform(sourcePlatformDocumentContext);
                    if (platform != null)
                    {
                        TransformGroup transformGroup = platform.GeometryHelper.ConvertTransformToWpf((object)documentCompositeNode);
                        if (PlatformConverter.IsPlatformValue((object)transformGroup, targetPlatformDocumentContext))
                        {
                            return(targetPlatformDocumentContext.CreateNode(typeof(TransformGroup), (object)transformGroup));
                        }
                    }
                }
                ITypeId typeId = (ITypeId)PlatformTypeHelper.ConvertTypeId((ITypeId)documentCompositeNode.Type, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                if (!documentCompositeNode.TypeResolver.PlatformMetadata.IsNullType(typeId))
                {
                    DocumentCompositeNode node1 = targetPlatformDocumentContext.CreateNode(typeId);
                    foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode.Properties)
                    {
                        IProperty property = this.ConvertPropertyKey(keyValuePair.Key, targetPlatformDocumentContext.TypeResolver.PlatformMetadata);
                        if (property != null)
                        {
                            DocumentNode node2 = keyValuePair.Value;
                            if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)node2.Type) && !PlatformTypes.Style.IsAssignableFrom((ITypeId)node2.Type))
                            {
                                DocumentNode node3 = this.ConvertSubtree(node2, sourcePlatformDocumentContext, targetPlatformDocumentContext);
                                if (node3 != null && (PlatformTypeHelper.GetPropertyType(property).IsAssignableFrom(node3.TargetType) || DocumentNodeUtilities.IsMarkupExtension(node3)))
                                {
                                    node1.Properties[(IPropertyId)property] = node3;
                                }
                            }
                        }
                    }
                    if (documentCompositeNode.SupportsChildren)
                    {
                        for (int index = 0; index < documentCompositeNode.Children.Count; ++index)
                        {
                            DocumentNode node2 = documentCompositeNode.Children[index];
                            node1.Children.Add(this.ConvertSubtree(node2, sourcePlatformDocumentContext, targetPlatformDocumentContext));
                        }
                    }
                    return((DocumentNode)node1);
                }
            }
            return((DocumentNode)null);
        }