Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public DataContextInfo Evaluate(IDataContextAncestorWalker walker, bool isForSettingValue)
        {
            this.visitedLocations.Reset();
            DataContextInfo       dataContextInfo1    = new DataContextInfo();
            RawDataSourceInfoBase dataSourceInfoBase1 = (RawDataSourceInfoBase)null;
            bool flag = isForSettingValue;

            this.evaluatingInfo = dataContextInfo1;
            DataContextInfo dataContextInfo2 = (DataContextInfo)null;

            try
            {
                while (walker.MoveNext())
                {
                    if (flag)
                    {
                        flag = DataContextMetadata.GetDataContextAttribute <DualDataContextAttribute>(walker.CurrentProperty) != null;
                    }
                    RawDataSourceInfoBase dataSourceInfoBase2 = !flag?this.NavigateSpecialDataContextInternal(walker, dataSourceInfoBase1, true) : dataSourceInfoBase1;

                    flag = false;
                    if (dataSourceInfoBase2 != dataSourceInfoBase1)
                    {
                        dataSourceInfoBase1 = dataSourceInfoBase2;
                        this.MoveUpIfDataContextLocation(walker);
                    }
                    if (dataSourceInfoBase1 != null)
                    {
                        if (!dataSourceInfoBase1.IsValid)
                        {
                            break;
                        }
                    }
                    RawDataSourceInfoBase rawDataContextInfo = this.GetRawDataContextInfo(walker);
                    if (rawDataContextInfo != null)
                    {
                        if (rawDataContextInfo.IsValid)
                        {
                            dataSourceInfoBase1 = rawDataContextInfo.CombineWith(dataSourceInfoBase1);
                        }
                        else if (dataSourceInfoBase1 != null)
                        {
                            dataSourceInfoBase1.SetInvalid();
                        }
                        else
                        {
                            dataSourceInfoBase1 = rawDataContextInfo;
                        }
                    }
                    if (dataSourceInfoBase1 != null)
                    {
                        if (dataSourceInfoBase1.IsValid)
                        {
                            if (dataSourceInfoBase1.HasSource)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (dataContextInfo2 == null)
                    {
                        dataContextInfo2 = this.GetTypedTemplateDataContext(walker.CurrentNode, dataSourceInfoBase1);
                    }
                }
            }
            finally
            {
                this.evaluatingInfo = (DataContextInfo)null;
            }
            if (dataContextInfo2 != null && dataContextInfo2.DataSource.IsValidWithSource && (dataSourceInfoBase1 == null || !dataSourceInfoBase1.IsValid || !dataSourceInfoBase1.HasSource))
            {
                dataContextInfo1 = dataContextInfo2;
            }
            else
            {
                dataContextInfo1.RawDataSource = dataSourceInfoBase1;
            }
            return(dataContextInfo1);
        }