Пример #1
0
        private void ProcessDataTemplate(DataBindingProcessingContext context, DocumentCompositeNode resolvedTemplateNode)
        {
            IType targetType = this.GetTargetType(resolvedTemplateNode, DataTemplateElement.DataTypeProperty);

            if (targetType == null)
            {
                this.ProcessResource(context, resolvedTemplateNode);
            }
            else
            {
                if (resolvedTemplateNode != context.DocumentCompositeNode)
                {
                    return;
                }
                RawDataSourceInfoBase dataContextFromType = this.GetDataContextFromType(targetType, resolvedTemplateNode.Properties[DataTemplateElement.DataTypeProperty]);
                if (dataContextFromType == null)
                {
                    return;
                }
                this.ProcessDocumentNodeChildren(new DataBindingProcessingContext((DocumentNode)resolvedTemplateNode, (DataBindingProcessingContext)null)
                {
                    DataContext = dataContextFromType
                });
            }
        }
Пример #2
0
        private RawDataSourceInfoBase InitDataContext(DataBindingProcessingContext context)
        {
            if (PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)context.DocumentNode.Type))
            {
                return((RawDataSourceInfoBase)RawDataSourceInfo.NewEmpty);
            }
            if (DataContextHelper.IsDataContextProperty((DocumentNode)context.ParentNode, (IPropertyId)context.Property))
            {
                return(context.GrandparentDataContext);
            }
            DataBindingProcessor.DataContextWalker dataContextWalker = new DataBindingProcessor.DataContextWalker(context.ParentContext, context.Property, this.namedElementDataContexts);
            RawDataSourceInfoBase localDataContext = this.DataContextEvaluator.NavigateSpecialDataContext((IDataContextAncestorWalker)dataContextWalker, (RawDataSourceInfoBase)null);

            if (localDataContext == null)
            {
                RawDataSourceInfoBase rawDataContextInfo = this.DataContextEvaluator.GetRawDataContextInfo(context.DocumentCompositeNode);
                localDataContext = this.DataContextEvaluator.UnwindElementNameBinding((IDataContextAncestorWalker)dataContextWalker, rawDataContextInfo);
            }
            this.DataContextEvaluator.MoveUpIfDataContextLocation((IDataContextAncestorWalker)dataContextWalker);
            if (localDataContext is ElementDataSourceInfo)
            {
                return(localDataContext);
            }
            if (dataContextWalker.CurrentContext != null)
            {
                localDataContext = this.CombineDataSources(dataContextWalker.CurrentContext.DataContext, localDataContext);
            }
            if (localDataContext == null)
            {
                localDataContext = (RawDataSourceInfoBase)RawDataSourceInfo.NewEmpty;
            }
            return(localDataContext);
        }
Пример #3
0
        private void ProcessDocumentNodeChildren(DataBindingProcessingContext context)
        {
            DocumentCompositeNode documentCompositeNode = context.DocumentCompositeNode;

            if (documentCompositeNode == null)
            {
                return;
            }
            if (!string.IsNullOrEmpty(documentCompositeNode.Name))
            {
                this.namedElementDataContexts[documentCompositeNode] = context;
            }
            foreach (KeyValuePair <IProperty, DocumentNode> keyValuePair in (IEnumerable <KeyValuePair <IProperty, DocumentNode> >)documentCompositeNode.Properties)
            {
                DocumentCompositeNode childNode = keyValuePair.Value as DocumentCompositeNode;
                if (childNode != null)
                {
                    this.ProcessDocumentNodeChild(context, childNode, keyValuePair.Key);
                }
                else
                {
                    this.ProcessDataContextPathExtension(context, keyValuePair.Value, keyValuePair.Key);
                }
            }
            if (!documentCompositeNode.SupportsChildren)
            {
                return;
            }
            for (int index = 0; index < documentCompositeNode.Children.Count; ++index)
            {
                DocumentCompositeNode childNode = documentCompositeNode.Children[index] as DocumentCompositeNode;
                this.ProcessDocumentNodeChild(context, childNode, (IProperty)null);
            }
        }
Пример #4
0
 public void ProcessDocument(SceneDocument sceneDocument, DataBindingProcessingOptions options)
 {
     if (sceneDocument.DocumentRoot == null || sceneDocument.DocumentRoot.RootNode == null)
     {
         return;
     }
     this.EnsureInitialized(sceneDocument.ProjectContext);
     this.DocumentRoot = sceneDocument.DocumentRoot;
     if (!this.documenNamedElementDataContexts.TryGetValue(this.DocumentRoot, out this.namedElementDataContexts))
     {
         this.namedElementDataContexts = new Dictionary <DocumentCompositeNode, DataBindingProcessingContext>();
         this.documenNamedElementDataContexts[this.DocumentRoot] = this.namedElementDataContexts;
     }
     if ((options & DataBindingProcessingOptions.FirstPass) == DataBindingProcessingOptions.FirstPass)
     {
         DataBindingProcessingContext context = new DataBindingProcessingContext(sceneDocument.DocumentRoot.RootNode, (DataBindingProcessingContext)null);
         context.DataContext = this.InitDataContext(context);
         this.ProcessDocumentNode(context);
         this.ProcessPendingBindings();
     }
     if ((options & DataBindingProcessingOptions.SecondPass) != DataBindingProcessingOptions.SecondPass)
     {
         return;
     }
     this.ProcessPendingBindings();
 }
Пример #5
0
 private void ProcessStyle(DataBindingProcessingContext context, DocumentCompositeNode styleNode)
 {
     if (!context.IsEmptyDataContext && !this.VerifyStyleTargetType(context, styleNode))
     {
         return;
     }
     this.ProcessResource(context, styleNode);
 }
Пример #6
0
 private void ProcessControlTemplate(DataBindingProcessingContext context, DocumentCompositeNode templateNode)
 {
     if (!context.IsEmptyDataContext && !this.VerifyControlTemplateTargetType(context, templateNode))
     {
         return;
     }
     this.ProcessResource(context, templateNode);
 }
 public DataBindingProcessingContext(DocumentNode rootNode, DataBindingProcessingContext outerContext)
 {
     this.DocumentNode          = rootNode;
     this.DocumentCompositeNode = this.DocumentNode as DocumentCompositeNode;
     this.DataContext           = outerContext != null ? outerContext.DataContext : (RawDataSourceInfoBase)RawDataSourceInfo.NewEmpty;
     this.Scope        = !PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)rootNode.Type) ? (!PlatformTypes.Style.IsAssignableFrom((ITypeId)rootNode.Type) ? (!PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)rootNode.Type) ? ProcessingContextScope.Normal : ProcessingContextScope.ControlTemplate) : ProcessingContextScope.Style) : ProcessingContextScope.DataTemplate;
     this.OuterContext = outerContext;
 }
Пример #8
0
        private RawDataSourceInfoBase GetRelativeSourceTargetBindingDataSource(DataBindingProcessingContext context)
        {
            if (context.OuterContext == null || !context.IsStyleOrControlTemplateScope)
            {
                return((RawDataSourceInfoBase)null);
            }
            string bindingRelativeSource = this.GetBindingRelativeSource(context);

            if (string.IsNullOrEmpty(bindingRelativeSource))
            {
                return((RawDataSourceInfoBase)null);
            }
            DataBindingProcessingContext context1 = (DataBindingProcessingContext)null;

            if (context.Scope == ProcessingContextScope.Style && bindingRelativeSource == "Self")
            {
                if (context.OuterContext != null)
                {
                    context1 = context.OuterContext.ParentContext;
                }
            }
            else if (context.Scope == ProcessingContextScope.ControlTemplate && bindingRelativeSource == "TemplatedParent")
            {
                context1 = this.GetTemplatedParentContext(context);
            }
            if (context1 == null || PlatformTypes.DictionaryEntry.IsAssignableFrom((ITypeId)context1.DocumentNode.Type))
            {
                return((RawDataSourceInfoBase)null);
            }
            string bindingPath = DataContextHelper.GetBindingPath(context.DocumentCompositeNode);

            if (string.IsNullOrEmpty(bindingPath))
            {
                return((RawDataSourceInfoBase)null);
            }
            IList <ClrPathPart> parts = ClrPropertyPathHelper.SplitPath(bindingPath);

            if (parts == null || parts.Count == 0)
            {
                return((RawDataSourceInfoBase)null);
            }
            ClrPathPart clrPathPart = parts[0];

            if (clrPathPart.Category != ClrPathPartCategory.PropertyName)
            {
                return((RawDataSourceInfoBase)null);
            }
            RawDataSourceInfoBase sourceFromProperty = this.GetDataSourceFromProperty(context1, clrPathPart.Path);

            if (sourceFromProperty == null || !sourceFromProperty.IsValid)
            {
                return((RawDataSourceInfoBase)null);
            }
            string path = ClrPropertyPathHelper.CombinePathParts(parts, 1);

            sourceFromProperty.AppendClrPath(path);
            return(sourceFromProperty);
        }
Пример #9
0
        private void ProcessDocumentNodeChild(DataBindingProcessingContext context, DocumentCompositeNode childNode, IProperty property)
        {
            if (childNode == null)
            {
                return;
            }
            DataBindingProcessingContext context1 = new DataBindingProcessingContext(context, (DocumentNode)childNode, property);

            context1.DataContext = this.InitDataContext(context1);
            this.ProcessDocumentNode(context1);
        }
Пример #10
0
 public bool AddToProcessedContextsIfNeeded(DataBindingProcessingContext context)
 {
     DataBindingProcessor.ResourceProcessingContext.Context context1 = new DataBindingProcessor.ResourceProcessingContext.Context(context.DataContext.SourceNode, context.DataContext.NormalizedClrPath);
     if (this.visitedContexts.BinarySearch(context1, (IComparer <DataBindingProcessor.ResourceProcessingContext.Context>)DataBindingProcessor.ResourceProcessingContext.ContextComparer.Instance) >= 0)
     {
         return(false);
     }
     this.visitedContexts.Add(context1);
     this.visitedContexts.Sort((IComparer <DataBindingProcessor.ResourceProcessingContext.Context>)DataBindingProcessor.ResourceProcessingContext.ContextComparer.Instance);
     return(true);
 }
Пример #11
0
        private RawDataSourceInfoBase GetBindingAsDataSource(DataBindingProcessingContext context)
        {
            RawDataSourceInfoBase sourceInfoFromBinding = DataContextHelper.GetDataSourceInfoFromBinding(context.DocumentCompositeNode);
            RawDataSourceInfoBase dataSourceInfoBase    = this.CombineDataSources(context.DataContext, sourceInfoFromBinding);

            if (!dataSourceInfoBase.IsValid)
            {
                dataSourceInfoBase = this.GetRelativeSourceTargetBindingDataSource(context);
            }
            return(dataSourceInfoBase);
        }
Пример #12
0
        private bool VerifyControlTemplateTargetType(DataBindingProcessingContext context, DocumentCompositeNode templateNode)
        {
            IType targetType = this.GetTargetType(templateNode, ControlTemplateElement.TargetTypeProperty);

            if (targetType == null)
            {
                return(true);
            }
            DocumentCompositeNode parentNode = context.ParentNode;

            return(parentNode != null && (targetType.IsAssignableFrom((ITypeId)parentNode.Type) || PlatformTypes.Setter.IsAssignableFrom((ITypeId)parentNode.Type) && context.Scope == ProcessingContextScope.Style));
        }
Пример #13
0
        private RawDataSourceInfoBase GetDataSourceFromProperty(DataBindingProcessingContext context, string propertyName)
        {
            IType                 type = context.DocumentNode.Type;
            MemberAccessTypes     allowableMemberAccess = TypeHelper.GetAllowableMemberAccess((ITypeResolver)this.ProjectContext, type);
            IProperty             property           = type.GetMember(MemberType.Property, propertyName, allowableMemberAccess) as IProperty;
            RawDataSourceInfoBase dataSourceInfoBase = (RawDataSourceInfoBase)null;

            if (property != null)
            {
                dataSourceInfoBase = this.GetDataSourceFromProperty(context, property);
            }
            return(dataSourceInfoBase);
        }
Пример #14
0
        private DataBindingProcessingContext GetTemplatedParentContext(DataBindingProcessingContext context)
        {
            DataBindingProcessingContext outerContext;

            for (outerContext = context.OuterContext; outerContext != null && outerContext.Scope == ProcessingContextScope.Style; outerContext = outerContext.OuterContext)
            {
                DocumentCompositeNode parentNode = outerContext.ParentNode;
                if (parentNode == null || !PlatformTypes.Setter.IsAssignableFrom((ITypeId)parentNode.Type))
                {
                    break;
                }
            }
            return(outerContext.ParentContext);
        }
Пример #15
0
        private void ProcessDataContextPathExtension(DataBindingProcessingContext context, DocumentNode childNode, IProperty property)
        {
            if (!PlatformTypes.String.IsAssignableFrom((ITypeId)childNode.Type) || DataContextMetadata.GetDataContextAttribute <DataContextPathExtensionAttribute>(property) == null)
            {
                return;
            }
            DataBindingProcessingContext context1 = new DataBindingProcessingContext(context, childNode, property);

            context1.DataContext = this.InitDataContext(context1);
            if (!this.ShouldProcess(context1.DataContext))
            {
                return;
            }
            this.HandleDataContextPathExtension(context1, context1.DataContext);
        }
Пример #16
0
 private void ProcessResource(DataBindingProcessingContext context, DocumentCompositeNode resourceNode)
 {
     DataBindingProcessor.ResourceProcessingContext processingContext;
     if (!this.processedResources.TryGetValue((DocumentNode)resourceNode, out processingContext))
     {
         processingContext = new DataBindingProcessor.ResourceProcessingContext();
         this.processedResources[(DocumentNode)resourceNode] = processingContext;
     }
     if (processingContext.IsProcessing || !processingContext.AddToProcessedContextsIfNeeded(context))
     {
         return;
     }
     using (processingContext.StartProcessing())
         this.ProcessDocumentNodeChildren(new DataBindingProcessingContext((DocumentNode)resourceNode, context));
 }
Пример #17
0
        private string GetBindingRelativeSource(DataBindingProcessingContext context)
        {
            DocumentCompositeNode documentCompositeNode = context.DocumentCompositeNode.Properties[BindingSceneNode.RelativeSourceProperty] as DocumentCompositeNode;

            if (documentCompositeNode == null || documentCompositeNode.Properties.Count != 1)
            {
                return((string)null);
            }
            DocumentPrimitiveNode documentPrimitiveNode = documentCompositeNode.Properties[0] as DocumentPrimitiveNode;

            if (documentPrimitiveNode == null || !PlatformTypes.RelativeSourceMode.IsAssignableFrom((ITypeId)documentPrimitiveNode.Type))
            {
                return((string)null);
            }
            return(documentPrimitiveNode.GetValue <string>());
        }
Пример #18
0
        private RawDataSourceInfoBase GetDataSourceFromProperty(DataBindingProcessingContext context, IProperty property)
        {
            if (DataContextHelper.GetDataContextProperty(context.DocumentNode.Type) == property)
            {
                return(context.DataContext);
            }
            DocumentNode dataSourceNode = context.DocumentCompositeNode.Properties[(IPropertyId)property];

            if (dataSourceNode == null)
            {
                return((RawDataSourceInfoBase)null);
            }
            RawDataSourceInfoBase rawDataSourceInfo = DataContextHelper.GetRawDataSourceInfo(dataSourceNode);

            return(this.CombineDataSources(context.DataContext, rawDataSourceInfo));
        }
 public DataBindingProcessingContext(DataBindingProcessingContext parentContext, DocumentNode childNode, IProperty parentProperty)
 {
     this.ParentContext         = parentContext;
     this.DocumentNode          = childNode;
     this.DocumentCompositeNode = this.DocumentNode as DocumentCompositeNode;
     this.Property = parentProperty;
     if (parentContext != null)
     {
         this.Scope        = parentContext.Scope;
         this.OuterContext = parentContext.OuterContext;
     }
     if (!PlatformTypes.ResourceDictionary.IsAssignableFrom((ITypeId)childNode.Type))
     {
         return;
     }
     this.Scope = ProcessingContextScope.ResourceDictionary;
 }
Пример #20
0
        private void ProcessDocumentNode(DataBindingProcessingContext context)
        {
            DocumentCompositeNode documentCompositeNode1 = context.DocumentCompositeNode;

            if (documentCompositeNode1.Type.IsBinding)
            {
                this.ProcessBinding(context);
            }
            else
            {
                if (!this.ShouldProcessDocumentNode(context))
                {
                    return;
                }
                DocumentCompositeNode documentCompositeNode2 = this.ResolveResourceReferenceIfNeeded(documentCompositeNode1);
                if (documentCompositeNode2 != null)
                {
                    if (PlatformTypes.DataTemplate.IsAssignableFrom((ITypeId)documentCompositeNode2.Type))
                    {
                        this.ProcessDataTemplate(context, documentCompositeNode2);
                        return;
                    }
                    if (PlatformTypes.Style.IsAssignableFrom((ITypeId)documentCompositeNode2.Type))
                    {
                        this.ProcessStyle(context, documentCompositeNode2);
                        return;
                    }
                    if (PlatformTypes.ControlTemplate.IsAssignableFrom((ITypeId)documentCompositeNode2.Type))
                    {
                        this.ProcessControlTemplate(context, documentCompositeNode2);
                        return;
                    }
                    if (ProjectNeutralTypes.ChangePropertyAction.IsAssignableFrom((ITypeId)documentCompositeNode2.Type))
                    {
                        this.ProcessChangePropertyAction(context);
                        return;
                    }
                    if (documentCompositeNode2 != documentCompositeNode1 && PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)documentCompositeNode2.Type))
                    {
                        this.ProcessResource(context, documentCompositeNode2);
                        return;
                    }
                }
                this.ProcessDocumentNodeChildren(context);
            }
        }
Пример #21
0
        private void ProcessChangePropertyAction(DataBindingProcessingContext context)
        {
            INodeSourceContext    containerContext = (INodeSourceContext)null;
            DocumentCompositeNode bindingNode      = context.DocumentCompositeNode.GetValue(DataBindingProcessor.ChangePropetyActionTargetObject, out containerContext) as DocumentCompositeNode;

            if (bindingNode == null || !bindingNode.Type.IsBinding)
            {
                return;
            }
            RawDataSourceInfoBase sourceInfoFromBinding = DataContextHelper.GetDataSourceInfoFromBinding(bindingNode);
            RawDataSourceInfoBase bindingInfo           = this.CombineDataSources(context.DataContext, sourceInfoFromBinding);

            if (!bindingInfo.IsValid)
            {
                bindingInfo = this.GetRelativeSourceTargetBindingDataSource(context);
            }
            if (bindingInfo == null || !bindingInfo.IsValid)
            {
                return;
            }
            this.HandleBinding(context, bindingInfo);
        }
Пример #22
0
        private void ProcessBinding(DataBindingProcessingContext context)
        {
            RawDataSourceInfoBase bindingAsDataSource = this.GetBindingAsDataSource(context);

            if (bindingAsDataSource == null || !bindingAsDataSource.IsValid)
            {
                return;
            }
            if (!bindingAsDataSource.HasSource && context.Scope != ProcessingContextScope.ResourceDictionary)
            {
                ElementDataSourceInfo bindingInfo = bindingAsDataSource as ElementDataSourceInfo;
                if (bindingInfo != null)
                {
                    this.pendingBindings.Add(new DataBindingProcessor.PendingBindingInfo(context, bindingInfo));
                }
            }
            if (!this.ShouldProcessDataSourceType(bindingAsDataSource.SourceType))
            {
                return;
            }
            this.HandleBinding(context, bindingAsDataSource);
        }
Пример #23
0
        private bool VerifyStyleTargetType(DataBindingProcessingContext context, DocumentCompositeNode styleNode)
        {
            IType targetType = this.GetTargetType(styleNode, StyleNode.TargetTypeProperty);

            if (targetType == null)
            {
                return(true);
            }
            if (context.Property == null)
            {
                return(false);
            }
            DocumentCompositeNode parentNode = context.ParentNode;
            Type propertyTargetType          = parentNode.Type.Metadata.GetStylePropertyTargetType((IPropertyId)context.Property);

            if (propertyTargetType == (Type)null)
            {
                return(context.Property.Equals((object)StyleNode.BasedOnProperty));
            }
            IType type = parentNode.TypeResolver.GetType(propertyTargetType);

            return(targetType.IsAssignableFrom((ITypeId)type));
        }
Пример #24
0
 private bool MoveNextInternal(ref DataBindingProcessor.DataContextWalker.ContextLocation location)
 {
     if (location == null)
     {
         location = new DataBindingProcessor.DataContextWalker.ContextLocation(this.first.Context, this.first.Property);
         return(true);
     }
     if (location.Context.ParentContext != null)
     {
         DataBindingProcessingContext parentContext = location.Context.ParentContext;
         location = new DataBindingProcessor.DataContextWalker.ContextLocation(parentContext, location.Context.Property);
     }
     else
     {
         if (location.Context.OuterContext == null)
         {
             return(false);
         }
         DataBindingProcessingContext outerContext = location.Context.OuterContext;
         location = new DataBindingProcessor.DataContextWalker.ContextLocation(outerContext, outerContext.Property);
     }
     return(true);
 }
Пример #25
0
 protected abstract bool ShouldProcessDocumentNode(DataBindingProcessingContext context);
Пример #26
0
 public ContextLocation(DataBindingProcessingContext context, IProperty property)
 {
     this.Context  = context;
     this.Property = property;
 }
Пример #27
0
 public DataContextWalker(DataBindingProcessingContext context, IProperty property, Dictionary <DocumentCompositeNode, DataBindingProcessingContext> namedElementDataContexts)
 {
     this.namedElementDataContexts = namedElementDataContexts;
     this.current = this.first = new DataBindingProcessor.DataContextWalker.ContextLocation(context, property);
 }
Пример #28
0
 public PendingBindingInfo(DataBindingProcessingContext bindingContext, ElementDataSourceInfo bindingInfo)
 {
     this.BindingContext = bindingContext;
     this.BindingInfo    = bindingInfo;
 }
Пример #29
0
 protected abstract void HandleBinding(DataBindingProcessingContext context, RawDataSourceInfoBase bindingInfo);
Пример #30
0
 protected abstract void HandleDataContextPathExtension(DataBindingProcessingContext context, RawDataSourceInfoBase bindingInfo);