Exemple #1
0
        private static SceneNode FindHighestDataContextLocationWithoutSourcelessBindings(SceneNode upperBound, SceneNode lowerBound)
        {
            SceneNode sceneNode1  = (SceneNode)null;
            SceneNode childToSkip = lowerBound;

            for (SceneNode sceneNode2 = lowerBound; sceneNode2 != upperBound; sceneNode2 = sceneNode2.Parent)
            {
                if (sceneNode2 == null)
                {
                    return((SceneNode)null);
                }
                if (DataContextPlacementEvaluator.IsNodeWithoutSourcelessBindings(sceneNode2, sceneNode2 != lowerBound, childToSkip))
                {
                    if (DataContextHelper.GetDataContextProperty(sceneNode2.Type) != null)
                    {
                        sceneNode1  = sceneNode2;
                        childToSkip = sceneNode2;
                    }
                    if (sceneNode2.DocumentNode.NameScope != null)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            return(sceneNode1);
        }
Exemple #2
0
        public static DataContextInfo FindDataContextPlacement(SceneNode sceneNode, IProperty targetProperty, DataSourceInfo dataSourceInfo)
        {
            DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(sceneNode, (IPropertyId)targetProperty, true);

            if (!dataContextInfo.IsValid)
            {
                return((DataContextInfo)null);
            }
            if (dataContextInfo.Owner != null)
            {
                dataContextInfo.DataSourceMatch = dataContextInfo.DataSource.CompareSources(dataSourceInfo);
                if (dataContextInfo.DataSourceMatch == DataSourceMatchCriteria.Ignore)
                {
                    using (sceneNode.ViewModel.CreateEditTransaction("", true))
                    {
                        if (targetProperty != null)
                        {
                            sceneNode.ClearLocalValue((IPropertyId)targetProperty);
                        }
                        if (DataContextPlacementEvaluator.IsAnySourcelessBindings(sceneNode))
                        {
                            return((DataContextInfo)null);
                        }
                        SceneNode sourcelessBindings = DataContextPlacementEvaluator.FindHighestDataContextLocationWithoutSourcelessBindings(dataContextInfo.GetOwnerSceneNode(sceneNode.ViewModel), sceneNode);
                        if (sourcelessBindings == null)
                        {
                            dataContextInfo.Owner           = (DocumentCompositeNode)null;
                            dataContextInfo.Property        = (IProperty)null;
                            dataContextInfo.DataSourceMatch = DataSourceMatchCriteria.Ignore;
                        }
                        else
                        {
                            dataContextInfo.Owner           = (DocumentCompositeNode)sourcelessBindings.DocumentNode;
                            dataContextInfo.Property        = DataContextHelper.GetDataContextProperty(dataContextInfo.Owner.Type);
                            dataContextInfo.DataSourceMatch = DataSourceMatchCriteria.Any;
                        }
                    }
                }
            }
            else
            {
                SceneNode highestDataContextHost = DataContextPlacementEvaluator.GetHighestDataContextHost(sceneNode);
                if (highestDataContextHost == null)
                {
                    return((DataContextInfo)null);
                }
                dataContextInfo                 = new DataContextInfo();
                dataContextInfo.Owner           = (DocumentCompositeNode)highestDataContextHost.DocumentNode;
                dataContextInfo.DataSourceMatch = DataSourceMatchCriteria.Any;
            }
            return(dataContextInfo);
        }
Exemple #3
0
 private static bool IsNodeWithoutSourcelessBindings(SceneNode sceneNode, bool checkChildren, SceneNode childToSkip)
 {
     if (DataContextPlacementEvaluator.IsAnySourcelessBindings(sceneNode))
     {
         return(false);
     }
     if (!checkChildren)
     {
         return(true);
     }
     foreach (SceneNode sceneNode1 in sceneNode.GetAllContent())
     {
         if (sceneNode1 != childToSkip && !DataContextPlacementEvaluator.IsNodeWithoutSourcelessBindings(sceneNode1, true, (SceneNode)null))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #4
0
        private bool SetSourceAsDataContext(SceneNode target, IPropertyId targetPropertyId, ref DataSchemaNodePath bindingPath, bool testOnly)
        {
            if (target == null || targetPropertyId == null)
            {
                return(false);
            }
            IProperty property = target.ProjectContext.ResolveProperty(targetPropertyId);

            if (property == null)
            {
                return(false);
            }
            SceneNode sceneNode      = target;
            IProperty targetProperty = property;

            if (DataContextHelper.IsDataContextProperty(target.DocumentNode, (IPropertyId)property))
            {
                sceneNode      = sceneNode.Parent;
                targetProperty = (IProperty)null;
                if (sceneNode == null || sceneNode.Parent == null)
                {
                    return(false);
                }
            }
            DataSourceInfo  dataSourceInfo   = new DataSourceInfo(bindingPath);
            DataContextInfo contextPlacement = DataContextPlacementEvaluator.FindDataContextPlacement(sceneNode, targetProperty, dataSourceInfo);

            if (contextPlacement == null || contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Ignore)
            {
                return(false);
            }
            if (contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Exact || contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Compatible)
            {
                if (contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Exact)
                {
                    bindingPath = bindingPath.GetRelativeNodePath(bindingPath);
                }
                else if (!string.IsNullOrEmpty(contextPlacement.DataSource.Path))
                {
                    DataSchemaNodePath nodePathFromPath = bindingPath.Schema.GetNodePathFromPath(contextPlacement.DataSource.Path);
                    bindingPath = nodePathFromPath.GetRelativeNodePath(bindingPath);
                }
                return(true);
            }
            if (contextPlacement.DataSourceMatch == DataSourceMatchCriteria.Any && contextPlacement.Owner != null && (contextPlacement.Owner != target.DocumentNode || contextPlacement.Property == null || !contextPlacement.Property.Equals((object)property)))
            {
                IProperty dataContextProperty = DataContextHelper.GetDataContextProperty(contextPlacement.Owner.Type);
                if (dataContextProperty != null)
                {
                    SceneNode ownerSceneNode = contextPlacement.GetOwnerSceneNode(target.ViewModel);
                    SceneNode dataSource     = this.CreateDataSource(ownerSceneNode, bindingPath, true);
                    if (dataSource != null)
                    {
                        if (!testOnly)
                        {
                            BindingEditor.SetBindingOrData(ownerSceneNode, (IPropertyId)dataContextProperty, dataSource, bindingPath);
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }