Example #1
0
        public static RawDataSourceInfoBase GetDataSourceInfoFromBinding(DocumentCompositeNode bindingNode)
        {
            RawDataSourceInfoBase dataSourceInfoBase    = (RawDataSourceInfoBase)null;
            DocumentCompositeNode resourceReferenceNode = bindingNode.Properties[BindingSceneNode.SourceProperty] as DocumentCompositeNode;

            if (resourceReferenceNode == null)
            {
                dataSourceInfoBase = (RawDataSourceInfoBase)DataContextHelper.GetElementNameBinding(bindingNode);
            }
            if (dataSourceInfoBase == null)
            {
                string bindingPath = DataContextHelper.GetBindingPath(bindingNode);
                if (resourceReferenceNode != null && resourceReferenceNode.Type.IsResource)
                {
                    dataSourceInfoBase = DataContextHelper.GetDataSourceInfoFromResourceReference(resourceReferenceNode);
                    if (!dataSourceInfoBase.IsValid)
                    {
                        return(dataSourceInfoBase);
                    }
                    dataSourceInfoBase.AppendClrPath(bindingPath);
                }
                else
                {
                    dataSourceInfoBase = (RawDataSourceInfoBase) new RawDataSourceInfo((DocumentNode)resourceReferenceNode, bindingPath);
                }
            }
            string bindingXpath = DataContextHelper.GetBindingXPath(bindingNode);

            dataSourceInfoBase.XmlPath = XmlSchema.CombineXPaths(dataSourceInfoBase.XmlPath, bindingXpath);
            if (bindingNode.Properties[BindingSceneNode.RelativeSourceProperty] != null)
            {
                dataSourceInfoBase.SetInvalid();
            }
            return(dataSourceInfoBase);
        }
Example #2
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);
        }
        private RawDataSourceInfoBase MoveToElementNameBinding(IDataContextAncestorWalker walker, ElementDataSourceInfo elementBinding)
        {
            if (walker.CurrentNode == null || elementBinding == null || elementBinding.RootTargetProperty == null)
            {
                return((RawDataSourceInfoBase)null);
            }
            if (this.visitedLocations.IsVisited(walker))
            {
                return((RawDataSourceInfoBase)RawDataSourceInfo.Invalid);
            }
            this.OnDataSourceFound(walker.CurrentNode, walker.CurrentProperty);
            if (!walker.MoveTo(elementBinding.RootElement, elementBinding.RootTargetProperty, true))
            {
                return((RawDataSourceInfoBase)null);
            }
            DocumentNode          dataSourceNode     = elementBinding.RootElement.Properties[(IPropertyId)elementBinding.RootTargetProperty];
            RawDataSourceInfoBase dataSourceInfoBase = dataSourceNode != null?DataContextHelper.GetRawDataSourceInfo(dataSourceNode) : (RawDataSourceInfoBase)RawDataSourceInfo.NewEmpty;

            if (dataSourceInfoBase.IsValid)
            {
                dataSourceInfoBase.AppendClrPath(elementBinding.NormalizedClrPath);
            }
            return(dataSourceInfoBase);
        }