private IProperty GetSpecialDefaultBindingProperty(DataBindingDragDropFlags filteredDragFlags) { DataSchemaNodePath primaryAbsolutePath = this.DragModel.DataSource.PrimaryAbsolutePath; IProperty defaultBindingProperty = this.GetDefaultBindingProperty(filteredDragFlags, primaryAbsolutePath); if (!DataContextMetadata.HasDataContextAttributes(defaultBindingProperty)) { return((IProperty)null); } DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(this.DragModel.TargetNode, (IPropertyId)defaultBindingProperty, true); if (dataContextInfo.DataSource.SourceNode != primaryAbsolutePath.Schema.DataSource.DocumentNode) { return((IProperty)null); } DataSchemaNodePath nodePathFromPath = primaryAbsolutePath.Schema.GetNodePathFromPath(dataContextInfo.DataSource.Path); if (!nodePathFromPath.IsSubpathOf(primaryAbsolutePath)) { return((IProperty)null); } DataSchemaNodePath relativeNodePath = nodePathFromPath.GetRelativeNodePath(primaryAbsolutePath); if (relativeNodePath.CollectionDepth != 0) { return((IProperty)null); } this.DragModel.TargetPropertySpecialDataContext = relativeNodePath; return(defaultBindingProperty); }
internal static IPropertyId RefineDataContextProperty(SceneNode target, IPropertyId targetProperty, DocumentNode dataNode) { if (targetProperty.MemberType == MemberType.DesignTimeProperty || !DataContextHelper.IsDataContextProperty(target.DocumentNode, targetProperty)) { return(targetProperty); } SampleNonBasicType sampleNonBasicType = dataNode.Type as SampleNonBasicType; if (sampleNonBasicType != null) { if (!sampleNonBasicType.DeclaringDataSet.IsEnabledAtRuntime) { return(DesignTimeProperties.DesignDataContextProperty); } if (((DocumentCompositeNode)target.DocumentNode).Properties[targetProperty] != null) { DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(target, targetProperty, true); if (dataContextInfo.DataSource != null && !(dataContextInfo.DataSource.DataSourceType is SampleNonBasicType)) { return(DesignTimeProperties.DesignDataContextProperty); } } return(targetProperty); } if (PlatformTypes.IsExpressionInteractiveType(dataNode.Type.RuntimeType)) { return(DesignTimeProperties.DesignDataContextProperty); } return(targetProperty); }
private bool CreateControls(Point dropPoint) { using (SceneEditTransaction editTransaction = this.DragModel.Document.CreateEditTransaction(StringTable.UndoUnitDragDropCreateDataboundControl)) { DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(this.DragModel.TargetNode); DataSourceInfo other = new DataSourceInfo(new DataSchemaNodePath(this.DragModel.DataSource.PrimaryAbsoluteSchema, this.GetRelativeSchema().Root)); bool flag = false; if (dataContextInfo.DataSource == null || !dataContextInfo.DataSource.IsValidWithSource || dataContextInfo.DataSource.CompareSources(other) != DataSourceMatchCriteria.Exact) { flag = true; } IList <DataSchemaNodePath> relativeSchemaPaths = this.GetRelativeSchemaPaths(); CanvasLikeDataViewLayoutBuilder viewLayoutBuilder = new CanvasLikeDataViewLayoutBuilder(this.DragModel.InsertionPoint.InsertIndex, false); DocumentCompositeNode containerNode = (DocumentCompositeNode)this.DragModel.TargetNode.DocumentNode; DataViewFactory.GenerateDataView(this.DragModel.Platform, this.DragModel.DocumentContext, relativeSchemaPaths, DataViewCategory.Master, containerNode, (IDataViewLayoutBuilder)viewLayoutBuilder); if (flag) { viewLayoutBuilder.RebindFields(this.DragModel.ViewModel, this.DragModel.DataSource.PrimaryAbsoluteSchema, relativeSchemaPaths); } editTransaction.Update(); viewLayoutBuilder.ApplyActiveUserThemeStyle(this.DragModel.ViewModel); viewLayoutBuilder.CompleteLayout(this.DragModel.ViewModel, dropPoint); viewLayoutBuilder.SelectElements(this.DragModel.ViewModel); editTransaction.Commit(); } return(true); }
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); }
protected BaseFrameworkElement GetReusableDetailsContainer(bool setDataContextIfMissing, bool canCheckParent) { SceneElement sceneElement = this.DragModel.TargetNode as SceneElement; if (sceneElement == null) { return((BaseFrameworkElement)null); } if (!this.IsSupportedDetailsContainer(sceneElement) && canCheckParent) { sceneElement = sceneElement.Parent as SceneElement; if (sceneElement == null || !this.IsSupportedDetailsContainer(sceneElement)) { return((BaseFrameworkElement)null); } } DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate((SceneNode)sceneElement); if (dataContextInfo != null && dataContextInfo.RawDataSource != null) { DataSourceInfo other = new DataSourceInfo(this.DragModel.DetailsContainerSchemaPath); if (dataContextInfo.DataSource.CompareSources(other) == DataSourceMatchCriteria.Exact) { return((BaseFrameworkElement)sceneElement); } } DocumentCompositeNode documentCompositeNode = (DocumentCompositeNode)sceneElement.DocumentNode; if (documentCompositeNode.Properties[DesignTimeProperties.DesignDataContextProperty] != null || documentCompositeNode.Properties[BaseFrameworkElement.DataContextProperty] != null) { return((BaseFrameworkElement)null); } if (DataBindingDragDropHandler.ContainsDescendantsWithSourcelessBindings((DocumentNode)documentCompositeNode)) { return((BaseFrameworkElement)null); } if (setDataContextIfMissing) { this.DragModel.ViewModel.BindingEditor.CreateAndSetBindingOrData((SceneNode)sceneElement, DesignTimeProperties.DesignDataContextProperty, this.DragModel.DetailsContainerSchemaPath); this.LinkDetailsWithMasterControl(sceneElement); } return((BaseFrameworkElement)sceneElement); }
protected BaseFrameworkElement FindMasterControl(SceneElement detailsContainerElement) { DataContextEvaluator evaluator = new DataContextEvaluator(); DataSourceInfo targetDataSource = new DataSourceInfo(this.DragModel.DetailsContainerSchemaPath); ITypeId[] typeIdArray = new ITypeId[3] { PlatformTypes.Selector, ProjectNeutralTypes.DataGrid, ProjectNeutralTypes.TreeView }; List <IProperty> properties = new List <IProperty>(typeIdArray.Length); for (int index = 0; index < typeIdArray.Length; ++index) { IProperty property = (IProperty)this.ProjectContext.ResolveType(typeIdArray[index]).GetMember(MemberType.LocalProperty, "SelectedItem", MemberAccessTypes.Public); if (property != null && !properties.Contains(property)) { properties.Add(property); } } return(this.FindMasterControl(this.DragModel.ViewModel.ActiveEditingContainer, properties, detailsContainerElement, targetDataSource, evaluator)); }
protected bool UpdateRelativeSchemaPath() { DataSchemaNodePath primaryAbsolutePath = this.DragModel.DataSource.PrimaryAbsolutePath; this.DragModel.RelativeDropSchemaPath = primaryAbsolutePath; DataContextInfo dataContextInfo = new DataContextEvaluator().Evaluate(this.DragModel.TargetNode); if (dataContextInfo != null && dataContextInfo.DataSource.IsValidWithSource) { ISchema schema = primaryAbsolutePath.Schema; if (DesignDataHelper.CompareDataSources(dataContextInfo.DataSource.SourceNode, schema.DataSource.DocumentNode)) { DataSchemaNodePath nodePathFromPath = schema.GetNodePathFromPath(dataContextInfo.DataSource.Path); if (nodePathFromPath == null) { return(true); } if (nodePathFromPath.IsMethod) { return(false); } bool flag = nodePathFromPath.IsSubpathOf(this.DragModel.DataSource[0].AbsolutePath); for (int index = 1; index < this.DragModel.DataSource.Count; ++index) { if (nodePathFromPath.IsSubpathOf(this.DragModel.DataSource[index].AbsolutePath) != flag) { return(false); } } if (flag) { this.DragModel.RelativeDropSchemaPath = nodePathFromPath.GetRelativeNodePath(primaryAbsolutePath); } } } return(true); }
protected bool IsMasterControl(SceneNode sceneNode, IProperty selectedItemProperty, DataSourceInfo targetDataSource, DataContextEvaluator evaluator) { if (!selectedItemProperty.DeclaringType.IsAssignableFrom((ITypeId)sceneNode.Type)) { return(false); } DataContextInfo dataContextInfo = evaluator.Evaluate(sceneNode, (IPropertyId)selectedItemProperty, false); return(targetDataSource.CompareSources(dataContextInfo.DataSource) == DataSourceMatchCriteria.Exact); }
protected BaseFrameworkElement FindMasterControl(SceneNode sceneNode, List <IProperty> properties, SceneElement detailsContainerElement, DataSourceInfo targetDataSource, DataContextEvaluator evaluator) { if (sceneNode == null || sceneNode == detailsContainerElement) { return((BaseFrameworkElement)null); } for (int index = 0; index < properties.Count; ++index) { if (this.IsMasterControl(sceneNode, properties[index], targetDataSource, evaluator)) { return((BaseFrameworkElement)sceneNode); } } IProperty defaultContentProperty = sceneNode.Type.Metadata.DefaultContentProperty; if (defaultContentProperty == null) { return((BaseFrameworkElement)null); } foreach (SceneNode sceneNode1 in (IEnumerable <SceneNode>)sceneNode.GetCollectionForProperty((IPropertyId)defaultContentProperty)) { BaseFrameworkElement masterControl = this.FindMasterControl((SceneNode)(sceneNode1 as SceneElement), properties, detailsContainerElement, targetDataSource, evaluator); if (masterControl != null) { return(masterControl); } } return((BaseFrameworkElement)null); }