Exemple #1
0
        public override bool Instantiate(IInstanceBuilderContext context, ViewNode viewNode)
        {
            TemplateBindingInstanceBuilderBase.CheckForInvalidBinding(viewNode);
            bool flag = base.Instantiate(context, viewNode);

            if (context.RootTargetTypeReplacement != null && context.IsSerializationScope)
            {
                ViewNode viewNode1 = StyleControlTemplateHelper.FindContainingControlTemplate(viewNode);
                if (viewNode1 != null)
                {
                    ViewNode viewNode2 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode1);
                    if (viewNode2 == null || viewNode2 == context.ViewNodeManager.Root)
                    {
                        DocumentCompositeNode documentNode = viewNode.DocumentNode as DocumentCompositeNode;
                        if (documentNode != null && DocumentNodeUtilities.IsTemplateBinding(documentNode))
                        {
                            IMemberId valueAsMember = DocumentNodeHelper.GetValueAsMember(documentNode, KnownProperties.TemplateBindingPropertyProperty);
                            if (valueAsMember != null)
                            {
                                IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(valueAsMember as IProperty);
                                if (replacementProperty != null && replacementProperty is DependencyPropertyReferenceStep && replacementProperty != valueAsMember)
                                {
                                    DocumentCompositeNode instance = (DocumentCompositeNode)viewNode.Instance;
                                    instance.Properties[KnownProperties.TemplateBindingPropertyProperty] = context.DocumentContext.CreateNode(PlatformTypes.DependencyProperty, new DocumentNodeMemberValue(replacementProperty));
                                }
                            }
                        }
                    }
                }
            }
            return(flag);
        }
Exemple #2
0
        public static DocumentNode GetShadowPropertyNode(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode)
        {
            IType valueAsType;
            DocumentNodeMemberValue value;
            ReferenceStep           member;

            if (!context.UseShadowProperties || propertyKey == null || !KnownProperties.SetterPropertyProperty.Equals(propertyKey))
            {
                return(null);
            }
            if (context.ContainerRoot == null || !PlatformTypes.Style.IsAssignableFrom(context.ContainerRoot.Type))
            {
                return(null);
            }
            DocumentCompositeNode documentNode = (DocumentCompositeNode)context.ContainerRoot.DocumentNode;
            DocumentPrimitiveNode item         = documentNode.Properties[KnownProperties.StyleTargetTypeProperty] as DocumentPrimitiveNode;

            if (item != null)
            {
                valueAsType = DocumentPrimitiveNode.GetValueAsType(item);
            }
            else
            {
                valueAsType = null;
            }
            IType type = valueAsType;

            if (type == null)
            {
                return(null);
            }
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;

            if (documentPrimitiveNode != null)
            {
                value = documentPrimitiveNode.Value as DocumentNodeMemberValue;
            }
            else
            {
                value = null;
            }
            DocumentNodeMemberValue documentNodeMemberValue = value;

            if (documentNodeMemberValue != null)
            {
                member = documentNodeMemberValue.Member as ReferenceStep;
            }
            else
            {
                member = null;
            }
            ReferenceStep referenceStep = member;

            if (referenceStep == null)
            {
                return(null);
            }
            if (context.RootTargetTypeReplacement != null)
            {
                ViewNode viewNode1 = StyleControlTemplateHelper.FindStyleTemplateOwningViewNode(viewNode);
                if (viewNode1 == null || viewNode1 == viewNode.ViewNodeManager.Root)
                {
                    IProperty replacementProperty = context.RootTargetTypeReplacement.GetReplacementProperty(referenceStep);
                    if (replacementProperty != null && replacementProperty != referenceStep)
                    {
                        return(context.DocumentContext.CreateNode(valueNode.Type, new DocumentNodeMemberValue(replacementProperty)));
                    }
                }
            }
            IProperty shadowProperty = DesignTimeProperties.GetShadowProperty(referenceStep, type);

            if (shadowProperty == null)
            {
                return(null);
            }
            if (!DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, shadowProperty))
            {
                return(null);
            }
            DocumentPrimitiveNode documentPrimitiveNode1 = context.DocumentContext.CreateNode(valueNode.Type, new DocumentNodeMemberValue(shadowProperty));

            return(documentPrimitiveNode1);
        }