Exemplo n.º 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);
        }
Exemplo n.º 2
0
 protected virtual bool IsValueValidForVerification(DocumentNode valueNode)
 {
     if (!DocumentNodeUtilities.IsBinding(valueNode) && !DocumentNodeUtilities.IsTemplateBinding(valueNode))
     {
         return(!DocumentNodeUtilities.IsStaticExtension(valueNode));
     }
     return(false);
 }
Exemplo n.º 3
0
 private object InternalGetAmbientValue(ReferenceStep property, SceneNode targetNode)
 {
     AmbientPropertyManager.AmbientPropertyValue ambientPropertyValue = this.GetAmbientPropertyValue(property);
     if (ambientPropertyValue != null)
     {
         if (ambientPropertyValue.Value == DependencyProperty.UnsetValue)
         {
             return(ambientPropertyValue.DefaultValue);
         }
         DocumentNode node = ambientPropertyValue.Value as DocumentNode;
         if (node == null)
         {
             return(DependencyProperty.UnsetValue);
         }
         if (targetNode == null && (DocumentNodeUtilities.IsStaticResource(node) || DocumentNodeUtilities.IsDynamicResource(node) || DocumentNodeUtilities.IsTemplateBinding(node)))
         {
             return(ambientPropertyValue.DefaultValue);
         }
         DocumentCompositeNode documentCompositeNode = node as DocumentCompositeNode;
         if (DocumentNodeUtilities.IsStaticResource(node) || DocumentNodeUtilities.IsDynamicResource(node))
         {
             DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(documentCompositeNode);
             bool         flag        = new ExpressionEvaluator((IDocumentRootResolver)targetNode.ProjectContext).EvaluateResource(targetNode.DocumentNodePath, DocumentNodeUtilities.IsStaticResource(node) ? ResourceReferenceType.Static : ResourceReferenceType.Dynamic, resourceKey) != null;
             if (!flag)
             {
                 object instance = targetNode.ViewModel.CreateInstance(new DocumentNodePath(resourceKey, resourceKey));
                 if (instance != null)
                 {
                     flag = targetNode.ViewModel.FindResource(instance) != null;
                 }
             }
             if (!flag)
             {
                 return(ambientPropertyValue.DefaultValue);
             }
         }
         else if (DocumentNodeUtilities.IsTemplateBinding(node))
         {
             ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator((IDocumentRootResolver)targetNode.ProjectContext);
             if (documentCompositeNode == null || expressionEvaluator.EvaluateTemplateBinding(targetNode.DocumentNodePath, documentCompositeNode) == null)
             {
                 return(ambientPropertyValue.DefaultValue);
             }
         }
         return((object)node);
     }
     if (targetNode == null || !object.Equals(ambientPropertyValue.DefaultValue, targetNode.GetDefaultValueAsWpf((IPropertyId)property)))
     {
         return(ambientPropertyValue.DefaultValue);
     }
     return(DependencyProperty.UnsetValue);
 }
Exemplo n.º 4
0
        private static void CheckForInvalidBinding(ViewNode viewNode)
        {
            if (viewNode == null || viewNode.DocumentNode == null || viewNode.DocumentNode.Parent == null || !viewNode.DocumentNode.IsProperty)
            {
                return;
            }
            IProperty sitePropertyKey = viewNode.DocumentNode.SitePropertyKey;

            if (KnownProperties.ContentControlContentProperty.Equals(sitePropertyKey) || KnownProperties.ContentPresenterContentProperty.Equals(sitePropertyKey))
            {
                DocumentCompositeNode documentNode = (DocumentCompositeNode)viewNode.DocumentNode;
                if (DocumentNodeUtilities.IsTemplateBinding(documentNode) && documentNode.Properties[KnownProperties.TemplateBindingPropertyProperty] == null)
                {
                    CultureInfo currentCulture = CultureInfo.CurrentCulture;
                    string      invalidBindingToVisualTreeElement = ExceptionStringTable.InvalidBindingToVisualTreeElement;
                    object[]    name = new object[] { sitePropertyKey.Name };
                    throw new InvalidOperationException(string.Format(currentCulture, invalidBindingToVisualTreeElement, name));
                }
            }
        }