diff --git a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_TreeView_Reorder_Automated.cs b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_TreeView_Reorder_Automated.cs
index 6f45c7aef470..38af39b9120a 100644
--- a/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_TreeView_Reorder_Automated.cs
+++ b/src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml/DragAndDropTests/DragDrop_TreeView_Reorder_Automated.cs
@@ -5,6 +5,7 @@
using Uno.UITest.Helpers.Queries;
using System.Linq;
using System;
+using System.Threading.Tasks;
namespace SamplesApp.UITests.Windows_UI_Xaml.DragAndDropTests
{
@@ -25,6 +26,10 @@ public void When_Dragging_TreeView_Item()
var bt2 = _app.Marked("bt2");
var bt3 = _app.Marked("bt3");
var focusbt = _app.Marked("focusbt");
+ var radio_disable = _app.Marked("radio_disable");
+
+ _app.WaitForElement(radio_disable);
+ _app.Tap(radio_disable);
_app.WaitForElement(tv);
_app.Tap(bt1);
@@ -64,5 +69,34 @@ public void When_Dragging_TreeView_Item()
result = _app.Screenshot("result3");
ImageAssert.AreEqual(case3, result);
}
+
+ [Test]
+ [AutoRetry]
+ [ActivePlatforms(Platform.Browser)]
+ public void When_OnDragItemsCompleted()
+ {
+ Run("UITests.Windows_UI_Xaml.DragAndDrop.DragDrop_TreeView", skipInitialScreenshot: true);
+ var tv = _app.Marked("tv");
+ var bt0 = _app.Marked("bt0");
+ var radio_enable = _app.Marked("radio_enable");
+ var tb = _app.Marked("tb");
+
+ _app.WaitForElement(tv);
+
+ _app.WaitForElement(radio_enable);
+ _app.Tap(radio_enable);
+ _app.WaitForElement(bt0);
+ _app.Tap(bt0);
+
+ var tvBounds = _app.Query("tv").Single().Rect;
+ float fromX = tvBounds.X + 100;
+ float fromY = tvBounds.Y + _itemHeight * 3 + _offset;
+ float toX = tvBounds.X + 100;
+ float toY = tvBounds.Y + _offset;
+ _app.DragCoordinates(fromX, fromY, toX, toY);
+
+ string text = _app.GetText("tb").Trim();
+ Assert.AreEqual("DragItemsCompleted is triggered", text);
+ }
}
}
diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml
index 9849384f35f9..501054dde76d 100644
--- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml
+++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml
@@ -24,5 +24,8 @@
+
+
+
diff --git a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml.cs b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml.cs
index c1ab88e6e470..54fb3a80a817 100644
--- a/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml.cs
+++ b/src/SamplesApp/UITests.Shared/Windows_UI_Xaml/DragAndDrop/DragDrop_TreeView.xaml.cs
@@ -124,6 +124,22 @@ public DragDrop_TreeView()
});
};
+ tv.DragItemsCompleted += (s, e) =>
+ {
+ tb.Text = "DragItemsCompleted is triggered";
+ };
+
+ radio_disable.Checked += (s, e) =>
+ {
+ tb.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
+ };
+
+ radio_enable.Checked += (s, e) =>
+ {
+ tb.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
+ };
+
+ radio_disable.IsChecked = true;
}
}
}
diff --git a/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs b/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs
index 8acbe8c66810..9df04898ba2b 100644
--- a/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs
+++ b/src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.DragDrop.cs
@@ -96,11 +96,9 @@ private static void PrepareContainerForDragDropCore(UIElement itemContainer)
// Known issue: the ContainerClearedForItem might not be invoked properly for all items on some platforms.
// This patch is acceptable as event handlers are static (so they won't leak).
itemContainer.DragStarting -= OnItemContainerDragStarting;
- itemContainer.DropCompleted -= OnItemContainerDragCompleted;
itemContainer.CanDrag = true;
itemContainer.DragStarting += OnItemContainerDragStarting;
- itemContainer.DropCompleted += OnItemContainerDragCompleted;
}
private static void ClearContainerForDragDrop(UIElement itemContainer)
@@ -112,7 +110,6 @@ private static void ClearContainerForDragDrop(UIElement itemContainer)
itemContainer.CanDrag = false;
itemContainer.DragStarting -= OnItemContainerDragStarting;
- itemContainer.DropCompleted -= OnItemContainerDragCompleted;
itemContainer.DragEnter -= OnReorderDragUpdated;
itemContainer.DragOver -= OnReorderDragUpdated;
@@ -124,6 +121,9 @@ private static void OnItemContainerDragStarting(UIElement sender, DragStartingEv
{
if (ItemsControlFromItemContainer(sender) is ListViewBase that && that.CanDragItems)
{
+ // only raise DragItemsCompleted if DragItemsStarting was raised
+ sender.DropCompleted -= OnItemContainerDragCompleted;
+ sender.DropCompleted += OnItemContainerDragCompleted;
// The items contains all selected items ONLY if the draggedItem is selected.
var draggedItem = that.ItemFromContainer(sender);
var items =
@@ -166,6 +166,7 @@ private static void OnItemContainerDragStarting(UIElement sender, DragStartingEv
that.ChangeSelectorItemsVisualState(true);
}
}
+
}
private static void OnItemContainerDragCompleted(UIElement sender, DropCompletedEventArgs innerArgs)
@@ -191,6 +192,7 @@ private static void OnItemContainerDragCompleted(UIElement sender, DropCompleted
// (eg if drag was released outside bounds of list)
that.CleanupReordering();
}
+ sender.DropCompleted -= OnItemContainerDragCompleted;
}
private static void OnReorderDragUpdated(object sender, _DragEventArgs dragEventArgs)