From 404bd9580ab4e7a604c8c6784d7fe0c327b1ee44 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 19 Oct 2019 14:01:51 -0500 Subject: [PATCH] add 'SelectItemOnDrop' prop to DragDropListBox --- .../DragDropItemsControl/DragDropListBox.xaml.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/client/spark/view/Controls/DragDropItemsControl/DragDropListBox.xaml.cs b/src/client/spark/view/Controls/DragDropItemsControl/DragDropListBox.xaml.cs index e5986df2f..61881d4c7 100644 --- a/src/client/spark/view/Controls/DragDropItemsControl/DragDropListBox.xaml.cs +++ b/src/client/spark/view/Controls/DragDropItemsControl/DragDropListBox.xaml.cs @@ -49,6 +49,8 @@ namespace mbts.ui.controls }; } + public bool SelectItemOnDrop { get; set; } + private DragIndicatorAdorner _adorner; private IDisposable _drag_operation; @@ -56,9 +58,13 @@ namespace mbts.ui.controls protected override DependencyObject GetContainerForItemOverride() { var container = new DraggableListBoxItem(); - container.MouseEnter += (s, e) => _adorner.InvalidateVisual(); - container.MouseLeave += (s, e) => _adorner.InvalidateVisual(); + container.MouseEnter += on_mouse_changed; + container.MouseLeave += on_mouse_changed; + container.MouseMove += on_mouse_changed; return container; + // + void on_mouse_changed(object sender, MouseEventArgs e) => + _adorner.InvalidateVisual(); } protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { @@ -89,6 +95,8 @@ namespace mbts.ui.controls if (source != null && target != null) { CoerceValue(DragDropManagerProperty); DragDropManager.Drop(source, target.Content); + if (SelectItemOnDrop && target is ListBoxItem lbi) + lbi.SetCurrentValue(ListBoxItem.IsSelectedProperty, true); } }