Skip to content

Commit

Permalink
fix(TreeView): allow dragging and dropping of treeview items
Browse files Browse the repository at this point in the history
  • Loading branch information
tprr7 committed Aug 21, 2023
1 parent 36c06c9 commit 50e0552
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected override void OnDrop(Windows.UI.Xaml.DragEventArgs args)

if (droppedNode != droppedOnNode)
{
((TreeViewNodeVector)droppedOnNode.Parent.Children).RemoveAt(removeIndex);
((TreeViewNodeVector)droppedNode.Parent.Children).RemoveAt(removeIndex);

// Append the dragged dropped item as a child of the node it was dropped onto
((TreeViewNodeVector)droppedOnNode.Children).Append(droppedNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public TreeViewList()

internal TreeViewViewModel ListViewModel { get; private set; }

internal TreeViewNode DraggedTreeViewNode { get; private set; }
internal TreeViewNode DraggedTreeViewNode
{
get
{
return m_draggedTreeViewNode;
}
}

private void OnDragItemsStarting(object sender, DragItemsStartingEventArgs args)
{
Expand Down
43 changes: 42 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/ItemsStackPanel/ItemsStackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Uno;
using Uno.Extensions;
using Uno.Extensions.Specialized;
using Uno.UI;
using Windows.UI.Xaml.Media;

namespace Windows.UI.Xaml.Controls
{
public partial class ItemsStackPanel : Panel, IVirtualizingPanel
public partial class ItemsStackPanel : Panel, IVirtualizingPanel, IInsertionPanel
{
VirtualizingPanelLayout _layout;

Expand Down Expand Up @@ -58,6 +62,43 @@ private void CreateLayoutIfNeeded()
#endif
}
}

void IInsertionPanel.GetInsertionIndexes(Windows.Foundation.Point position, out int first, out int second)
{
first = -1;
second = -1;
if ((new Windows.Foundation.Rect(0, 0, ActualSize.X, ActualSize.Y)).Contains(position))
{
if (Children == null || Children.Empty())
{
return;
}
if (Orientation == Orientation.Vertical)
{
foreach (var child in Children)
{
if (position.Y >= child.ActualOffset.Y + child.ActualSize.Y / 2)
{
first++;
}
}
}
else
{
foreach (var child in Children)
{
if (position.X >= child.ActualOffset.X + child.ActualSize.X / 2)
{
first++;
}
}
}
if (first + 1 < Children.Count)
{
second = first + 1;
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ private static void OnItemContainerDragStarting(UIElement sender, DragStartingEv
that.DragLeave -= OnReorderDragLeave;
that.Drop -= OnReorderCompleted;

that.DragEnter += OnReorderDragUpdated;
that.DragOver += OnReorderDragUpdated;
that.DragLeave += OnReorderDragLeave;
that.Drop += OnReorderCompleted;

if (that is not Microsoft.UI.Xaml.Controls.TreeViewList)
{
that.DragEnter += OnReorderDragUpdated;
that.DragOver += OnReorderDragUpdated;
that.DragLeave += OnReorderDragLeave;
that.Drop += OnReorderCompleted;
}
that.m_tpPrimaryDraggedContainer = sender as SelectorItem;

that.ChangeSelectorItemsVisualState(true);
Expand Down

0 comments on commit 50e0552

Please sign in to comment.