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); }
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 static ElementDataSourceInfo GetElementNameBinding(DocumentCompositeNode bindingNode) { DocumentNode node = bindingNode.Properties[BindingSceneNode.ElementNameProperty]; if (node == null) { return((ElementDataSourceInfo)null); } string valueAsString = DocumentPrimitiveNode.GetValueAsString(node); if (string.IsNullOrEmpty(valueAsString)) { return(ElementDataSourceInfo.Invalid); } DocumentCompositeNode namedElement = node.FindContainingNameScope().FindNode(valueAsString) as DocumentCompositeNode; if (namedElement == null) { return(ElementDataSourceInfo.Invalid); } string bindingPath = DataContextHelper.GetBindingPath(bindingNode); return(new ElementDataSourceInfo(namedElement, bindingPath)); }