private void ApplyRulesInternal(DataBindingDragDropModel model, DataBindingDragDropFlags filteredDragFlags) { if ((filteredDragFlags & DataBindingDragDropFlags.SetBinding) == DataBindingDragDropFlags.SetBinding) { if (model.InsertionPoint.Property != null) { model.DropFlags &= ~DataBindingDragDropFlags.SetBinding; IType type = model.RelativeDropSchemaPath.Type; if (type != null && BindingPropertyHelper.GetPropertyCompatibility(model.InsertionPoint.Property, type, (ITypeResolver)model.TargetNode.ProjectContext) != BindingPropertyCompatibility.None) { model.TargetProperty = model.InsertionPoint.Property; model.DropFlags |= DataBindingDragDropFlags.SetBinding; } } else if ((filteredDragFlags & DataBindingDragDropFlags.AutoPickProperty) == DataBindingDragDropFlags.AutoPickProperty) { model.TargetProperty = this.GetSpecialDefaultBindingProperty(filteredDragFlags); if (model.TargetProperty == null) { model.TargetProperty = this.GetDefaultBindingProperty(filteredDragFlags, model.RelativeDropSchemaPath); } if (model.TargetProperty != null) { model.DropFlags |= DataBindingDragDropFlags.SetBinding; } } } if ((filteredDragFlags & DataBindingDragDropFlags.CreateElement) != DataBindingDragDropFlags.CreateElement || !PlatformTypes.Panel.IsAssignableFrom((ITypeId)model.TargetNode.Type)) { return; } if (DataBindingModeModel.Instance.NormalizedMode == DataBindingMode.Default && model.RelativeDropSchemaPath.IsCollection) { model.NewElementType = !model.RelativeDropSchemaPath.IsHierarchicalCollection ? DataBindingDragDropDefaultHandler.ItemsControlType : DataBindingDragDropDefaultHandler.TreeControlType; model.NewElementProperty = (IPropertyId)model.NewElementType.GetMember(MemberType.LocalProperty, "ItemsSource", MemberAccessTypes.Public); model.DropFlags |= DataBindingDragDropFlags.CreateElement; } List <DataSchemaNode> toCreateElements = this.GetNodesToCreateElements(); if (toCreateElements.Count < model.DataSource.Count) { return; } model.DropFlags |= DataBindingDragDropFlags.CreateElement; model.NodesToCreateElements = (IList <DataSchemaNode>)toCreateElements; if (model.NewElementType != null) { return; } IType dataType = toCreateElements[0].ResolveType(model.TargetNode.DocumentNode.TypeResolver); DataViewTemplateEntry viewTemplateEntry = DataViewFactory.GetDataViewTemplateEntry(model.Platform, dataType, DataViewCategory.Master); model.NewElementType = (ITypeId)viewTemplateEntry.FieldNode.Type; model.NewElementProperty = (IPropertyId)viewTemplateEntry.FieldValueProperty; }
private List <DataSchemaNode> GetNodesToCreateElements() { IPlatform platform = this.DragModel.Platform; List <DataSchemaNode> list = new List <DataSchemaNode>(); bool flag = DataBindingModeModel.Instance.NormalizedMode == DataBindingMode.Default; DataViewCategory category = flag ? DataViewCategory.Master : DataViewCategory.Details; if (flag && this.DragModel.DataSource.Count == 1 && this.DragModel.DataSource.PrimarySchemaNodePath.IsCollection) { DataSchemaNode collectionItemNode = this.DragModel.DataSource.PrimarySchemaNodePath.EffectiveCollectionItemNode; IType type = collectionItemNode.ResolveType(this.DragModel.TargetNode.DocumentNode.TypeResolver); if (PlatformTypes.IConvertible.IsAssignableFrom((ITypeId)type) || PlatformTypes.ImageSource.IsAssignableFrom((ITypeId)type)) { list.Add(collectionItemNode); } else { foreach (DataSchemaNode dataSchemaNode in collectionItemNode.Children) { IType dataType = dataSchemaNode.ResolveType(this.DragModel.TargetNode.DocumentNode.TypeResolver); if (DataViewFactory.GetDataViewTemplateEntry(platform, dataType, category) != null) { list.Add(dataSchemaNode); } } } } else { for (int index = 0; index < this.DragModel.DataSource.Count; ++index) { DataSchemaNodePath dataSchemaNodePath = this.DragModel.DataSource[index]; if (DataViewFactory.GetDataViewTemplateEntry(platform, dataSchemaNodePath.Type, category) != null) { list.Add(dataSchemaNodePath.Node); } } } list.Sort((Comparison <DataSchemaNode>)((a, b) => StringLogicalComparer.Instance.Compare(a.PathName, b.PathName))); return(list); }