コード例 #1
0
        private static void StripFormatting(DocumentNode node)
        {
            node.SourceContext = (INodeSourceContext)null;
            DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;

            if (documentCompositeNode != null)
            {
                foreach (IPropertyId propertyKey in (IEnumerable <IProperty>)documentCompositeNode.Properties.Keys)
                {
                    documentCompositeNode.ClearContainerContext(propertyKey);
                }
            }
            foreach (DocumentNode node1 in node.ChildNodes)
            {
                ReplaceStyleTemplateCommand.StripFormatting(node1);
            }
        }
コード例 #2
0
        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);
        }