mirror of
https://github.com/egmont11/NetworkDiagram.git
synced 2026-07-24 07:09:43 +02:00
Fixed an issue where if you dragged a device to the screen, it used the last selected instead,
This commit is contained in:
@@ -75,10 +75,21 @@ namespace NetworkDiagram
|
||||
#region Drag and Drop (Toolbox to Canvas)
|
||||
private void Toolbox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (sender is ListBox { SelectedItem: DeviceTemplate template } listBox)
|
||||
DragDrop.DoDragDrop(listBox, template, DragDropEffects.Copy);
|
||||
if (sender is ListBox listBox)
|
||||
{
|
||||
// Find the item under the mouse instead of relying on SelectedItem
|
||||
var element = e.OriginalSource as DependencyObject;
|
||||
while (element != null && !(element is ListBoxItem))
|
||||
element = VisualTreeHelper.GetParent(element);
|
||||
|
||||
if (element is ListBoxItem item && item.Content is DeviceTemplate template)
|
||||
{
|
||||
DragDrop.DoDragDrop(listBox, template, DragDropEffects.Copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DiagramCanvas_DragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effects = e.Data.GetDataPresent(typeof(DeviceTemplate)) ? DragDropEffects.Copy : DragDropEffects.None;
|
||||
|
||||
Reference in New Issue
Block a user