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); }
protected RawDataSourceInfoBase CombineDataSources(RawDataSourceInfoBase inheritedDataContext, RawDataSourceInfoBase localDataContext) { if (localDataContext == null) { return(inheritedDataContext); } if (!localDataContext.IsValid || localDataContext.HasSource) { return(localDataContext); } ElementDataSourceInfo elementDataSourceInfo = localDataContext as ElementDataSourceInfo; RawDataSourceInfoBase localSource; if (elementDataSourceInfo == null) { localSource = inheritedDataContext == null || !inheritedDataContext.IsValid ? localDataContext : inheritedDataContext.CombineWith(localDataContext); } else { DataBindingProcessingContext context; if (!this.namedElementDataContexts.TryGetValue(elementDataSourceInfo.RootElement, out context)) { localSource = (RawDataSourceInfoBase)elementDataSourceInfo; } else { DataBindingProcessor.DataContextWalker dataContextWalker = new DataBindingProcessor.DataContextWalker(context, (IProperty)null, this.namedElementDataContexts); localSource = this.DataContextEvaluator.UnwindElementNameBinding((IDataContextAncestorWalker)dataContextWalker, (RawDataSourceInfoBase)elementDataSourceInfo); if (!(localSource is ElementDataSourceInfo)) { this.DataContextEvaluator.MoveUpIfDataContextLocation((IDataContextAncestorWalker)dataContextWalker); if (dataContextWalker.CurrentContext != null) { localSource = dataContextWalker.CurrentContext.DataContext.CombineWith(localSource); } } } } return(localSource); }