From 60e0d4eddb0a3a7475206375de9c213778c42918 Mon Sep 17 00:00:00 2001 From: celeron533 Date: Wed, 23 Jul 2025 16:28:04 +0800 Subject: [PATCH] Able to drag the result file to external 3rd party program. --- DicomGrep/MainWindow.xaml | 2 +- DicomGrep/MainWindow.xaml.cs | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/DicomGrep/MainWindow.xaml b/DicomGrep/MainWindow.xaml index cebc44e..6b690bc 100644 --- a/DicomGrep/MainWindow.xaml +++ b/DicomGrep/MainWindow.xaml @@ -124,7 +124,7 @@ - + diff --git a/DicomGrep/MainWindow.xaml.cs b/DicomGrep/MainWindow.xaml.cs index bf1127f..59b2fd0 100644 --- a/DicomGrep/MainWindow.xaml.cs +++ b/DicomGrep/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using DicomGrep.Views; +using DicomGrepCore.Entities; using System; using System.Collections.Generic; using System.Linq; @@ -21,6 +22,9 @@ namespace DicomGrep /// public partial class MainWindow : Window { + private Point _startDragPoint; + private ResultDicomFile _draggedFile; + public MainWindow() { InitializeComponent(); @@ -30,5 +34,49 @@ private void About_OnClick(object sender, RoutedEventArgs e) { new AboutView().ShowDialog(); } + + private void DataGrid_MouseMove(object sender, MouseEventArgs e) + { + if (_draggedFile == null) + { + return; + } + + Point currentPosition = e.GetPosition(null); + Vector dragDelta = currentPosition - _startDragPoint; + + if (e.LeftButton == MouseButtonState.Pressed && + (Math.Abs(dragDelta.X) > SystemParameters.MinimumHorizontalDragDistance || + Math.Abs(dragDelta.Y) > SystemParameters.MinimumVerticalDragDistance)) + { + string[] filePaths = { _draggedFile.FullFilename }; + DataObject dataObject = new DataObject(DataFormats.FileDrop, filePaths); + + DragDrop.DoDragDrop((DataGrid)sender, dataObject, DragDropEffects.Copy); + + _draggedFile = null; + } + } + + private void DataGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + _startDragPoint = e.GetPosition(null); + var dataGrid = sender as DataGrid; + var row = FindAncestor((DependencyObject)e.OriginalSource); + if (row != null) + { + _draggedFile = row.Item as ResultDicomFile; + } + } + + private T FindAncestor(DependencyObject dependencyObject) where T : DependencyObject + { + var parent = VisualTreeHelper.GetParent(dependencyObject); + + if (parent == null) return null; + + var parentT = parent as T; + return parentT ?? FindAncestor(parent); + } } }