add 'SelectItemOnDrop' prop to DragDropListBox
This commit is contained in:
1 parent
03bbb8a558
commit
404bd9580a
1 file changed
+10
-2
@@ -49,6 +49,8 @@ namespace mbts.ui.controls
|
||||
};
|
||||
}
|
||||
|
||||
public bool SelectItemOnDrop { get; set; }
|
||||
|
||||
private DragIndicatorAdorner<DraggableListBoxItem> _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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user