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); }
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); }