예제 #1
0
 public static bool DoesPropertyApply(SceneNode sceneNode, ReferenceStep referenceStep, SceneNode valueNode, out ReferenceStep appliedReferenceStep)
 {
     appliedReferenceStep = sceneNode.DesignerContext.PropertyManager.FilterProperty(sceneNode, referenceStep);
     if (appliedReferenceStep == null)
     {
         return(false);
     }
     if (DocumentNodeUtilities.IsStyleOrTemplate(appliedReferenceStep.PropertyType))
     {
         DocumentNode node = valueNode.DocumentNode;
         if (node.Type.IsExpression)
         {
             node = new ExpressionEvaluator(sceneNode.ViewModel.DocumentRootResolver).EvaluateExpression(sceneNode.DocumentNodePath, valueNode.DocumentNode);
         }
         if (node == null || !DocumentNodeUtilities.IsStyleOrTemplate(node.Type) || !appliedReferenceStep.PropertyType.IsAssignableFrom((ITypeId)node.Type))
         {
             return(false);
         }
         IType templateTargetType = DocumentNodeUtilities.GetStyleOrTemplateTargetType(node);
         Type  propertyTargetType = sceneNode.Metadata.GetStylePropertyTargetType((IPropertyId)appliedReferenceStep);
         if (templateTargetType != null && propertyTargetType != (Type)null && !templateTargetType.RuntimeType.IsAssignableFrom(propertyTargetType))
         {
             return(false);
         }
     }
     return(true);
 }
        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);
            }
        }
예제 #3
0
        protected bool BindsTwoWayByDefault(SceneNode targetNode, ReferenceStep targetProperty)
        {
            DependencyPropertyReferenceStep propertyReferenceStep = targetProperty as DependencyPropertyReferenceStep;

            if (propertyReferenceStep == null)
            {
                return(false);
            }
            Type targetType = targetNode.TargetType;

            if (DocumentNodeUtilities.IsStyleOrTemplate(targetNode.Type))
            {
                targetType = DocumentNodeUtilities.GetStyleOrTemplateTargetType(targetNode.DocumentNode).RuntimeType;
            }
            return(propertyReferenceStep.BindsTwoWayByDefault(targetType));
        }