private void SfTreeView_ItemDropping(object sender, TreeViewItemDroppingEventArgs e) { e.Handled = true; if (e.DraggingNodes != null && e.DraggingNodes[0].Content is ChunkViewModel source) { if (e.TargetNode.Content is ChunkViewModel target) { if (source.Data is RedBaseClass rbc) { if (target.Parent.Data is DataBuffer or SerializationDeferredDataBuffer) { target.Parent.AddChunkToDataBuffer((RedBaseClass)rbc.DeepCopy(), target.Parent.Properties.IndexOf(target) + 1); } if (target.Parent.Data is IRedArray arr) { var arrayType = target.Parent.Data.GetType().GetGenericTypeDefinition(); if (arrayType == typeof(CArray <>)) { target.Parent.AddClassToArray((RedBaseClass)rbc.DeepCopy(), target.Parent.Properties.IndexOf(target) + 1); } if (arrayType == typeof(CStatic <>) && arr.Count < arr.MaxSize) { target.Parent.AddClassToArray((RedBaseClass)rbc.DeepCopy(), target.Parent.Properties.IndexOf(target) + 1); } } } } } }
private void SfTreeView_ItemDropping(object sender, TreeViewItemDroppingEventArgs e) { e.Handled = true; if (e.DraggingNodes != null && e.DraggingNodes[0].Content is ChunkViewModel source) { if (e.TargetNode.Content is ChunkViewModel target) { if (source.Data is RedBaseClass rbc && target.Parent.Data is DataBuffer or SerializationDeferredDataBuffer) { target.Parent.AddChunkToDataBuffer((RedBaseClass)rbc.DeepCopy(), target.Parent.Properties.IndexOf(target) + 1); } } } }
private void TreeView_ItemDropping(object sender, TreeViewItemDroppingEventArgs e) { var dragSource = e.DragSource as SfTreeView; var dropSource = sender as SfTreeView; IList sourceCollection = null; if (dragSource == null || (dragSource != dropSource)) { var item = e.Data.GetData("Nodes") as ObservableCollection <TreeNode>; var treeNode = item[0] as TreeNode; var record = treeNode.Item as PersonInfo; var dropPosition = e.DropPosition.ToString(); var newItem = new PersonInfo(); if (e.TargetNode != null) { var itemInfo = AssociatedObject.treeView.GetItemInfo(e.TargetNode.Content); int rowIndex = (int)itemInfo.ItemIndex; if (dropPosition != "None" && rowIndex != -1) { var treeViewNode = AssociatedObject.treeView.GetNodeAtRowIndex(rowIndex); if (treeViewNode == null) { return; } var data = treeViewNode.Content; var itemIndex = -1; TreeViewNode parentNode = null; if (dropPosition == "DropBelow" || dropPosition == "DropAbove") { parentNode = treeViewNode.ParentNode; if (parentNode == null) { newItem = new PersonInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, DOB = record.DOB, Children = record.Children } } ; else { var parentkey = parentNode.Content as PersonInfo; newItem = new PersonInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, DOB = record.DOB, Children = record.Children }; } } else if (dropPosition == "DropAsChild") { if (!treeViewNode.IsExpanded) { AssociatedObject.treeView.ExpandNode(treeViewNode); } parentNode = treeViewNode; var parentkey = parentNode.Content as PersonInfo; newItem = new PersonInfo() { FirstName = record.FirstName, LastName = record.LastName, ID = record.ID, Children = record.Children }; } if (dropPosition == "DropBelow" || dropPosition == "DropAbove") { if (treeViewNode.ParentNode != null) { IEnumerable collection = null; if (AssociatedObject.treeView.HierarchyPropertyDescriptors != null && AssociatedObject.treeView.HierarchyPropertyDescriptors.Count > 0) { foreach (var propertyDescriptor in AssociatedObject.treeView.HierarchyPropertyDescriptors) { if (propertyDescriptor.TargetType == treeViewNode.ParentNode.Content.GetType()) { var descriptors = TypeDescriptor.GetProperties(treeViewNode.ParentNode.Content.GetType()); var tempItem = descriptors.Find(AssociatedObject.treeView.ChildPropertyName, true); if (tempItem != null) { collection = tempItem.GetValue(treeViewNode.ParentNode.Content) as IEnumerable; } break; } } } else { var descriptors = TypeDescriptor.GetProperties(treeViewNode.ParentNode.Content.GetType()); var tempItem = descriptors.Find(AssociatedObject.treeView.ChildPropertyName, true); if (tempItem != null) { collection = tempItem.GetValue(treeViewNode.ParentNode.Content) as IEnumerable; } } sourceCollection = GetSourceListCollection(collection); } else { sourceCollection = GetSourceListCollection(null); } itemIndex = sourceCollection.IndexOf(data); if (dropPosition == "DropBelow") { itemIndex += 1; } } else if (dropPosition == "DropAsChild") { var descriptors = TypeDescriptor.GetProperties(treeViewNode.Content.GetType()); if (parentNode != null) { IEnumerable collection = null; var tempItem = descriptors.Find(AssociatedObject.treeView.ChildPropertyName, true); if (tempItem != null) { collection = tempItem.GetValue(treeViewNode.Content) as IEnumerable; } if (collection != null) { sourceCollection = GetSourceListCollection(collection); } } if (sourceCollection == null) { var type = data.GetType().GetProperty(AssociatedObject.treeView.ChildPropertyName).PropertyType; var paramExp = System.Linq.Expressions.Expression.Parameter(type, type.Name); var instance = System.Linq.Expressions.Expression.MemberInit(System.Linq.Expressions.Expression.New(type), new List <MemberBinding>()); var lambda = System.Linq.Expressions.Expression.Lambda(instance, paramExp); var delg = lambda.Compile(); var list = delg.DynamicInvoke(new object[] { null }) as IList; if (list != null) { var tempitem = descriptors.Find(AssociatedObject.treeView.ChildPropertyName, true); tempitem.SetValue(treeViewNode.Content, list); sourceCollection = list; } itemInfo.Node.PopulateChildNodes(sourceCollection); } itemIndex = sourceCollection.Count; } sourceCollection.Insert(itemIndex, newItem); e.Handled = true; (AssociatedObject.treeGrid.ItemsSource as ObservableCollection <PersonInfo>).Remove(record as PersonInfo); } } else { sourceCollection = GetSourceListCollection(null); sourceCollection.Insert(0, record); (AssociatedObject.treeGrid.ItemsSource as ObservableCollection <PersonInfo>).Remove(record as PersonInfo); } } }