diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml
index 55dcb2c..fbff03e 100644
--- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml
+++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml
@@ -68,32 +68,30 @@
Background="#F5F5F5"
BorderBrush="{StaticResource PanelBorder}"
BorderThickness="0,1,0,1">
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
@@ -254,9 +203,6 @@
-
-
-
diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs
index 4132646..13867a4 100644
--- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs
+++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml.cs
@@ -5,6 +5,7 @@ using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
+using System.Windows.Threading;
using XP.Common.Logging.Interfaces;
using XplorePlane.Models;
using XplorePlane.ViewModels;
@@ -90,9 +91,14 @@ namespace XplorePlane.Views
}
_isInternalDragging = true;
+ _suppressClickToggle = true;
var data = new DataObject(PipelineNodeDragFormat, _draggedNode);
DragDrop.DoDragDrop(PipelineListBox, data, DragDropEffects.Move);
- _suppressClickToggle = true;
+ Dispatcher.BeginInvoke(new Action(() =>
+ {
+ _suppressClickToggle = false;
+ ResetDragState();
+ }), DispatcherPriority.Background);
}
private void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
@@ -195,29 +201,11 @@ namespace XplorePlane.Views
}
var oldIndex = vm.PipelineNodes.IndexOf(draggedNode);
- var targetIndex = GetDropTargetIndex(e.GetPosition(PipelineListBox));
- if (targetIndex < 0)
- {
- targetIndex = vm.PipelineNodes.Count - 1;
- }
+ var insertionIndex = GetDropInsertionIndex(e.GetPosition(PipelineListBox), vm.PipelineNodes.Count);
+ var newIndex = insertionIndex > oldIndex ? insertionIndex - 1 : insertionIndex;
+ newIndex = Math.Max(0, Math.Min(newIndex, vm.PipelineNodes.Count - 1));
- if (targetIndex >= oldIndex && targetIndex < vm.PipelineNodes.Count - 1)
- {
- var targetItem = GetItemAtPosition(e.GetPosition(PipelineListBox));
- if (targetItem != null)
- {
- var itemBounds = VisualTreeHelper.GetDescendantBounds(targetItem);
- var itemTopLeft = targetItem.TranslatePoint(new Point(0, 0), PipelineListBox);
- var itemMidY = itemTopLeft.Y + (itemBounds.Height / 2);
- if (e.GetPosition(PipelineListBox).Y > itemMidY)
- {
- targetIndex = Math.Min(targetIndex + 1, vm.PipelineNodes.Count - 1);
- }
- }
- }
-
- targetIndex = Math.Max(0, Math.Min(targetIndex, vm.PipelineNodes.Count - 1));
- if (oldIndex == targetIndex)
+ if (oldIndex == newIndex)
{
return;
}
@@ -225,16 +213,27 @@ namespace XplorePlane.Views
vm.ReorderOperatorCommand.Execute(new PipelineReorderArgs
{
OldIndex = oldIndex,
- NewIndex = targetIndex
+ NewIndex = newIndex
});
}
- private int GetDropTargetIndex(Point position)
+ private int GetDropInsertionIndex(Point position, int itemCount)
{
var item = GetItemAtPosition(position);
- return item == null
- ? -1
- : PipelineListBox.ItemContainerGenerator.IndexFromContainer(item);
+ if (item == null)
+ {
+ return itemCount;
+ }
+
+ var targetIndex = PipelineListBox.ItemContainerGenerator.IndexFromContainer(item);
+ if (targetIndex < 0)
+ {
+ return itemCount;
+ }
+
+ var itemTop = item.TranslatePoint(new Point(0, 0), PipelineListBox).Y;
+ var itemMid = itemTop + (item.ActualHeight / 2);
+ return position.Y > itemMid ? targetIndex + 1 : targetIndex;
}
private ListBoxItem GetItemAtPosition(Point position)
@@ -274,7 +273,12 @@ namespace XplorePlane.Views
var current = originalSource as DependencyObject;
while (current != null)
{
- if (current is ButtonBase || current is TextBoxBase || current is Selector || current is ScrollBar)
+ if (current is ListBoxItem)
+ {
+ return false;
+ }
+
+ if (current is ButtonBase || current is TextBoxBase || current is ScrollBar)
{
return true;
}