public void DragEnd(object sender, DragTreeViewItemAdvEventArgs e) { e.Cancel = false; TreeViewItemAdv drop = e.TargetDropItem as TreeViewItemAdv; if (drag != null && drop != null && drag.ParentItemsControl == drop.ParentItemsControl) { e.Cancel = true; } }
private void ServersTreeView_OnDragEnd(object sender, DragTreeViewItemAdvEventArgs e) { //Fix weird selections ServersTreeView.ClearSelection(); var draggingItems = new List <ServerTreeViewModel>(); foreach (var draggingItem in e.DraggingItems) { if (draggingItem.Header is ServerTreeViewModel st) { draggingItems.Add(st); } else { goto Skip; } } var types = new HashSet <ServerTreeViewType>(draggingItems.Select(items => items.Type)); if (types.Count == 1) { var type = types.First(); switch (type) { case ServerTreeViewType.Subtag: e.Cancel = !(e.TargetDropItem is TreeViewAdv); return; case ServerTreeViewType.Group: //移到相同订阅组上会被吃掉 if (e.DropIndex < 0) { goto Skip; } //属于同样的订阅 if (e.TargetDropItem is TreeViewItemAdv treeViewItem) { if (treeViewItem.Header is ServerTreeViewModel st && st.Type == ServerTreeViewType.Subtag) { if (draggingItems.All(draggingItem => draggingItem.Parent == st)) { e.Cancel = false; return; } } } break; case ServerTreeViewType.Server: //属于同一个订阅 var subs = new HashSet <string>(); foreach (var draggingItem in draggingItems) { var parent = draggingItem.Parent; while (parent.Parent != null) { parent = parent.Parent; } if (parent is ServerTreeViewModel parentModel) { subs.Add(parentModel.Name); continue; } goto Skip; } if (subs.Count != 1) { goto Skip; } var sub = subs.First(); //且 目标为群组或原版的订阅连接 if (e.TargetDropItem is TreeViewItemAdv treeViewItemAdv) { if (treeViewItemAdv.Header is ServerTreeViewModel st) { switch (st.Type) { case ServerTreeViewType.Subtag: { //移到相同订阅组上会被吃掉 if (e.DropIndex < 0) { goto Skip; } //原版的订阅连接 if (draggingItems.All(draggingItem => draggingItem.Parent == st)) { e.Cancel = false; return; } break; } case ServerTreeViewType.Group: { //相同订阅组 if (st.Parent is ServerTreeViewModel targetParent && sub == targetParent.Name) { //同一个组 var parents = new HashSet <IVirtualTree>(draggingItems.Select(items => items.Parent)); if (parents.Count != 1) { goto Skip; } var parent = parents.First(); if (e.DropIndex < 0 && parent == st) { goto Skip; } foreach (var draggingItem in draggingItems) { var first = st.Nodes.FirstOrDefault(); draggingItem.Server.Group = first != null ? first.Server.Group : st.Name != I18NUtil.GetAppStringValue(@"EmptyGroup") ? st.Name : string.Empty; draggingItem.Parent = st; } e.Cancel = false; return; } break; } } } } break; default: throw new ArgumentOutOfRangeException(); } } Skip: e.Cancel = true; }
void TreeViewAdv_DragStart(object sender, DragTreeViewItemAdvEventArgs e) { AddLog("DragStarted from ( " + (e.OriginalSource as TreeViewAdv).Name + " )"); }
void TreeViewAdv1_DragEnd(object sender, DragTreeViewItemAdvEventArgs e) { AddLog("DragEnd ( " + (e.OriginalSource as TreeViewAdv).Name + " )"); }
public void DragStart(object sender, DragTreeViewItemAdvEventArgs e) { drag = (sender as TreeViewAdv).SelectedContainer; }