예제 #1
0
        protected virtual DocumentNode GetDocumentNodeForDefaultStyle(IType targetType, IPropertyId propertyKey)
        {
            DocumentNode documentNode1 = this.ResolveDefaultStyleAsDocumentNode(targetType, propertyKey);
            DocumentNode documentNode2 = (DocumentNode)null;

            if (documentNode1 != null && documentNode1.DocumentRoot == this.ViewModel.DocumentRoot)
            {
                documentNode2 = (DocumentNode)this.DocumentContext.CreateNode(PlatformTypes.Style, (IDocumentNodeValue) new DocumentNodeReferenceValue(documentNode1));
            }
            if (documentNode2 == null)
            {
                if (documentNode1 != null)
                {
                    try
                    {
                        documentNode2 = documentNode1.Clone(this.DocumentContext);
                        ((DocumentCompositeNode)documentNode2).SetValue <bool>(DesignTimeProperties.IsDefaultStyleProperty, true);
                    }
                    catch (Exception ex)
                    {
                        return((DocumentNode)null);
                    }
                }
            }
            return(documentNode2);
        }
예제 #2
0
        public DocumentCompositeNode CreateResource(DocumentNode newResourceNode, IPropertyId targetTypeProperty, int index)
        {
            ResourceSite currentResourceSite = this.CurrentResourceSite;

            if (currentResourceSite == null)
            {
                return((DocumentCompositeNode)null);
            }
            IDocumentContext documentContext = currentResourceSite.DocumentContext;

            if (newResourceNode.Context != documentContext)
            {
                newResourceNode = newResourceNode.Clone(documentContext);
            }
            if (this.TargetType != (Type)null)
            {
                IType type = documentContext.TypeResolver.GetType(this.TargetType);
                ((DocumentCompositeNode)newResourceNode).Properties[targetTypeProperty] = (DocumentNode)documentContext.CreateNode(PlatformTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)type));
            }
            if (this.selectedLocation == this.thisDocumentResourceDictionaries && this.selectedResourceDictionary != null)
            {
                this.selectedResourceDictionary.Instance.EnsureResourceDictionaryNode();
                this.currentResourceSiteCacheValid = false;
            }
            DocumentNode keyNode;

            if (this.ApplyAutomatically)
            {
                keyNode = (DocumentNode)null;
            }
            else
            {
                string uniqueResourceKey = currentResourceSite.GetUniqueResourceKey(this.KeyString);
                keyNode = (DocumentNode)documentContext.CreateNode(uniqueResourceKey);
            }
            SceneDocument         externalDocument = this.ExternalDocument;
            DocumentCompositeNode resource;

            if (externalDocument != null)
            {
                using (SceneEditTransaction editTransaction = externalDocument.CreateEditTransaction(StringTable.PropertyCreateResourceInFileDescription))
                {
                    resource = currentResourceSite.CreateResource(keyNode, newResourceNode, index);
                    editTransaction.Commit();
                }
            }
            else
            {
                resource = currentResourceSite.CreateResource(keyNode, newResourceNode, index);
            }
            return(resource);
        }
예제 #3
0
        private static bool NodeTreesAreEquivalent(SceneViewModel viewModel, DocumentNode nodeA, DocumentNode nodeB)
        {
            nodeA = nodeA.Clone(viewModel.DocumentRoot.DocumentContext);
            ResourceHelper.StripOffFormatting(nodeA);
            nodeB = nodeB.Clone(viewModel.DocumentRoot.DocumentContext);
            ResourceHelper.StripOffFormatting(nodeB);
            DocumentCompositeNode node1 = nodeA.Context.CreateNode(PlatformTypes.DictionaryEntry);

            node1.Properties[node1.PlatformMetadata.KnownProperties.DictionaryEntryValue] = nodeA;
            DocumentCompositeNode node2 = nodeB.Context.CreateNode(PlatformTypes.DictionaryEntry);

            node2.Properties[node2.PlatformMetadata.KnownProperties.DictionaryEntryValue] = nodeB;
            XamlSerializer xamlSerializer = new XamlSerializer((IDocumentRoot)viewModel.XamlDocument, (IXamlSerializerFilter) new DefaultXamlSerializerFilter());

            return(xamlSerializer.Serialize(nodeA).Equals(xamlSerializer.Serialize(nodeB)));
        }
예제 #4
0
        public DocumentNode CreateResourceReference(IDocumentContext documentContext, DocumentCompositeNode resourceNode, bool useStaticResource)
        {
            DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(resourceNode);

            if (resourceEntryKey == null)
            {
                return((DocumentNode)null);
            }
            DocumentNode keyNode = resourceEntryKey.Clone(documentContext);

            if (useStaticResource)
            {
                return((DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode));
            }
            return((DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode));
        }
예제 #5
0
        public override void SetValueToLocalResource(SceneNodeProperty propertyKey, LocalResourceModel localResource)
        {
            DocumentNode resourceKey = localResource.ResourceKey;

            PerformanceUtility.StartPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
            SceneViewModel viewModel = this.ViewModel;

            if (viewModel != null)
            {
                IDocumentContext documentContext = viewModel.Document.DocumentContext;
                IProjectContext  projectContext  = viewModel.ProjectContext;
                DocumentNode     keyNode         = resourceKey.Clone(documentContext);
                bool             flag            = this.CanSetDynamicExpression && JoltHelper.TypeSupported((ITypeResolver)projectContext, PlatformTypes.DynamicResource);
                if (flag && this.ShouldAllowAnimation && (propertyKey.IsEnabledRecordCurrentValue && this.ViewModel.AnimationEditor.IsRecording))
                {
                    flag = false;
                }
                DocumentNode documentNode = !flag ? (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(documentContext, keyNode) : (DocumentNode)DocumentNodeUtilities.NewDynamicResourceNode(documentContext, keyNode);
                using (this.ShouldAllowAnimation ? (IDisposable)null : viewModel.AnimationEditor.DeferKeyFraming())
                {
                    string description = string.Format((IFormatProvider)CultureInfo.CurrentCulture, StringTable.PropertyChangeUndoDescription, new object[1]
                    {
                        (object)((PropertyEntry)propertyKey).get_PropertyName()
                    });
                    if (viewModel.Document.IsEditable)
                    {
                        using (SceneEditTransaction editTransaction = viewModel.CreateEditTransaction(description))
                        {
                            this.SetValue((PropertyReferenceProperty)propertyKey, (object)documentNode);
                            bool         isMixed;
                            DocumentNode valueAsDocumentNode = this.GetLocalValueAsDocumentNode(propertyKey, GetLocalValueFlags.CheckKeyframes, out isMixed);
                            if (!isMixed && valueAsDocumentNode != null)
                            {
                                Microsoft.Expression.DesignSurface.Utility.ResourceHelper.EnsureReferencedResourcesAreReachable(localResource.ResourceNode, valueAsDocumentNode);
                            }
                            editTransaction.Commit();
                        }
                    }
                }
            }
            PerformanceUtility.EndPerformanceSequence(PerformanceEvent.ApplyResource, "Apply resource.");
        }
예제 #6
0
 public void ApplyAmbientProperties(SceneNode node)
 {
     if (node == null || !Enumerable.Any <ITypeId>((IEnumerable <ITypeId>)AmbientPropertyManager.SupportedTypes, (Func <ITypeId, bool>)(type => type.IsAssignableFrom((ITypeId)node.Type))) || this.suppressApplyCount > 0)
     {
         return;
     }
     foreach (ReferenceStep referenceStep in this.GetResolvedAmbientProperties())
     {
         bool strictTypeCheck = true;
         PropertyReference propertyReference = SceneNodeObjectSet.FilterProperty(node, new PropertyReference(referenceStep), strictTypeCheck);
         if (propertyReference != null)
         {
             object       valueToSet    = this.InternalGetAmbientValue(referenceStep, node);
             DocumentNode documentNode1 = valueToSet as DocumentNode;
             if (documentNode1 != null)
             {
                 DocumentNode          documentNode2         = documentNode1.Clone(node.DocumentContext);
                 DocumentCompositeNode documentCompositeNode = documentNode2 as DocumentCompositeNode;
                 if (documentCompositeNode != null)
                 {
                     documentCompositeNode.ClearValue((IPropertyId)documentCompositeNode.Type.Metadata.NameProperty);
                 }
                 foreach (DocumentNode documentNode3 in documentNode2.SelectDescendantNodes((Predicate <DocumentNode>)(nodePredicate => nodePredicate.Parent.IsNameProperty((IPropertyId)nodePredicate.SitePropertyKey))))
                 {
                     documentNode3.Parent.ClearValue((IPropertyId)documentNode3.SitePropertyKey);
                 }
                 valueToSet = (object)documentNode2;
             }
             if (valueToSet == DependencyProperty.UnsetValue)
             {
                 node.ClearValueAsWpf(propertyReference);
             }
             else
             {
                 node.SetValueAsWpf(propertyReference, valueToSet);
             }
         }
     }
 }
예제 #7
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));
                 }
             }
         }
     }
 }
예제 #8
0
        private SceneNode CreateDataSource(SceneNode target, DataSchemaNodePath bindingPath, bool isSourcePathLess)
        {
            DocumentNode resourceKey = bindingPath.Schema.DataSource.ResourceKey;

            if (resourceKey == null)
            {
                if (!isSourcePathLess && !string.IsNullOrEmpty(bindingPath.Path))
                {
                    return((SceneNode)null);
                }
                DocumentNode documentNode   = bindingPath.Schema.DataSource.DocumentNode;
                IProjectItem designDataFile = DesignDataHelper.GetDesignDataFile(documentNode);
                DocumentNode node;
                if (designDataFile != null)
                {
                    node = DesignDataHelper.CreateDesignDataExtension(designDataFile, target.DocumentContext);
                }
                else
                {
                    if (PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)bindingPath.Schema.DataSource.DocumentNode.Type))
                    {
                        return((SceneNode)null);
                    }
                    node = documentNode.Clone(target.DocumentContext);
                }
                return(target.ViewModel.GetSceneNode(node));
            }
            if (!this.EnsureDataSourceReachable(target, bindingPath.Schema.DataSource))
            {
                return((SceneNode)null);
            }
            BindingSceneNode bindingSceneNode = BindingSceneNode.Factory.Instantiate(target.ViewModel);
            DocumentNode     keyNode          = resourceKey.Clone(target.DocumentContext);

            bindingSceneNode.Source = (DocumentNode)DocumentNodeUtilities.NewStaticResourceNode(keyNode.Context, keyNode);
            return((SceneNode)bindingSceneNode);
        }
예제 #9
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?();
        }
 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);
 }
        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);
        }
        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);
        }
예제 #13
0
        protected virtual DocumentNode ResolveDefaultStyleAsDocumentNode(IType targetType, IPropertyId propertyKey)
        {
            DocumentNode node      = (DocumentNode)null;
            IViewStyle   viewStyle = (IViewStyle)null;

            if (this.IsViewObjectValid)
            {
                ReferenceStep referenceStep = propertyKey as ReferenceStep;
                if (referenceStep != null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                {
                    viewStyle = this.Platform.ViewObjectFactory.Instantiate(referenceStep.GetCurrentValue(this.ViewObject.PlatformSpecificObject)) as IViewStyle;
                    if (viewStyle != null && viewStyle.StyleTargetType != targetType.RuntimeType)
                    {
                        viewStyle = (IViewStyle)null;
                    }
                    if (viewStyle != null)
                    {
                        node = this.ViewModel.DefaultView.GetCorrespondingDocumentNode((IViewObject)viewStyle, true);
                        if (node == null && this.DesignerContext.DesignerDefaultPlatformService.DefaultPlatform == this.Platform)
                        {
                            node = this.CreateNode(viewStyle.PlatformSpecificObject);
                        }
                    }
                }
            }
            for (IType type = this.ProjectContext.GetType(this.MetadataFactory.GetMetadata(targetType.RuntimeType).GetStylePropertyTargetType(propertyKey)); node == null && type != null && !PlatformTypes.Object.Equals((object)type); type = type.BaseType)
            {
                IList <DocumentCompositeNode> auxillaryResources = (IList <DocumentCompositeNode>)null;
                if (PlatformTypes.IsPlatformType((ITypeId)type))
                {
                    node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromPlatform(this.Platform, (object)type.RuntimeType, out auxillaryResources);
                }
                else
                {
                    foreach (IProject project in this.DesignerContext.ProjectManager.CurrentSolution.Projects)
                    {
                        IProjectContext projectContext = (IProjectContext)ProjectXamlContext.GetProjectContext(project);
                        if (projectContext != null && type.RuntimeAssembly.Equals((object)projectContext.ProjectAssembly))
                        {
                            node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromProject(project, (object)type.RuntimeType, out auxillaryResources);
                            if (node == null && !this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
                            {
                                node = this.DesignerContext.ThemeContentProvider.GetThemeResourceFromAssembly(this.ProjectContext, type.RuntimeAssembly, type.RuntimeAssembly, (object)type.RuntimeType, out auxillaryResources);
                            }
                        }
                    }
                }
                if (node != null)
                {
                    node = node.Clone(this.DocumentContext);
                    if (auxillaryResources != null && auxillaryResources.Count > 0)
                    {
                        StyleNode styleNode = (StyleNode)this.ViewModel.GetSceneNode(node);
                        if (styleNode.AreResourcesSupported)
                        {
                            if (styleNode.Resources == null)
                            {
                                styleNode.Resources = (ResourceDictionaryNode)this.ViewModel.CreateSceneNode(PlatformTypes.ResourceDictionary);
                            }
                            for (int index = auxillaryResources.Count - 1; index >= 0; --index)
                            {
                                DictionaryEntryNode dictionaryEntryNode = (DictionaryEntryNode)this.ViewModel.GetSceneNode(auxillaryResources[index].Clone(this.DocumentContext));
                                styleNode.Resources.Insert(0, dictionaryEntryNode);
                            }
                        }
                    }
                }
            }
            if (viewStyle == null && this.ProjectContext.IsCapabilitySet(PlatformCapability.IsWpf))
            {
                ReferenceStep referenceStep = propertyKey as ReferenceStep;
                if (referenceStep != null)
                {
                    System.Windows.Style style = referenceStep.GetDefaultValue(targetType.RuntimeType) as System.Windows.Style;
                    if (style != null)
                    {
                        node = this.CreateNode((object)style);
                    }
                }
            }
            return(node);
        }