Ejemplo n.º 1
0
        public SceneNode CreateAndSetBindingOrData(SceneNode target, IPropertyId targetProperty, DataSchemaNodePath bindingPath, bool useSourceInherited)
        {
            SceneNode bindingOrData = this.CreateBindingOrData(target, targetProperty, bindingPath, useSourceInherited);

            if (bindingOrData != null)
            {
                BindingEditor.SetBindingOrData(target, targetProperty, bindingOrData, bindingPath);
            }
            return(bindingOrData);
        }
Ejemplo n.º 2
0
        private static void SetBindingOrData(SceneNode targetNode, IPropertyId targetProperty, SceneNode bindingOrData, DataSchemaNodePath bindingPath)
        {
            BindingSceneNode binding = bindingOrData as BindingSceneNode;

            using (targetNode.ViewModel.AnimationEditor.DeferKeyFraming())
            {
                if (binding != null)
                {
                    IPropertyId propertyKey = targetProperty;
                    if (binding.Source != null)
                    {
                        propertyKey = BindingEditor.RefineDataContextProperty(targetNode, targetProperty, bindingPath.Schema.DataSource.DocumentNode);
                    }
                    targetNode.SetBinding(propertyKey, binding);
                }
                else
                {
                    IPropertyId propertyKey = BindingEditor.RefineDataContextProperty(targetNode, targetProperty, bindingOrData.DocumentNode);
                    targetNode.SetValueAsSceneNode(propertyKey, bindingOrData);
                }
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable <SceneNode> DataSourceItemEnumerator(SceneNode pivot)
        {
            BaseFrameworkElement   baseFrameworkElement;
            ResourceDictionaryNode resourceDictionaryNode;
            ApplicationSceneNode   applicationNode;
            ResourceDictionaryNode searchDictionary = (baseFrameworkElement = pivot as BaseFrameworkElement) == null ? ((resourceDictionaryNode = pivot as ResourceDictionaryNode) == null ? ((applicationNode = pivot as ApplicationSceneNode) == null ? (ResourceDictionaryNode)null : applicationNode.Resources) : resourceDictionaryNode) : baseFrameworkElement.Resources;

            if (searchDictionary != null)
            {
                foreach (DictionaryEntryNode dictionaryEntryNode in searchDictionary)
                {
                    if (dictionaryEntryNode != null && dictionaryEntryNode.Value != null && BindingEditor.IsDataSource(dictionaryEntryNode.Value.DocumentNode))
                    {
                        yield return((SceneNode)dictionaryEntryNode);
                    }
                }
                foreach (ResourceDictionaryNode resourceDictionaryNode1 in (IEnumerable <ResourceDictionaryNode>)searchDictionary.MergedDictionaries)
                {
                    foreach (DictionaryEntryNode dictionaryEntryNode in resourceDictionaryNode1)
                    {
                        if (dictionaryEntryNode != null && dictionaryEntryNode.Value != null && BindingEditor.IsDataSource(dictionaryEntryNode.Value.DocumentNode))
                        {
                            yield return((SceneNode)dictionaryEntryNode);
                        }
                    }
                }
            }
        }
Ejemplo n.º 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);
        }