private void OnMouseMove(object sender, MouseEventArgs e) { DataGrid dataGrid = sender as DataGrid; Point p = e.GetPosition(dataGrid); if (this.isMouseDown && (this.dragStartPoint - p).Length > 10) { List <FileDescriptor> files = new List <FileDescriptor>(); var items = dataGrid.SelectedItems.Cast <ExplorerItem>().ToList(); FindRecursive(files, items); this.numOfFiles = files.Count; this.copyIndex = 0; var virtualFileDataObject = new VirtualFileDataObject(Start, Stop, Pull); virtualFileDataObject.SetData(files); this.dlg = new ProgresshWindow() { Owner = Window.GetWindow(this) }; VirtualFileDataObject.DoDragDrop(dataGrid, virtualFileDataObject, DragDropEffects.Copy); this.isMouseDown = false; } }
private void OnDrop(object sender, DragEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Data.GetDataPresent(DataFormats.FileDrop)) { List <string> files = new List <string>(); string[] fileDrops = e.Data.GetData(DataFormats.FileDrop, true) as string[]; foreach (string file in fileDrops) { files.Add(file); // add directory content if (Directory.Exists(file)) { files.AddRange(Directory.EnumerateFileSystemEntries(file, "*", SearchOption.AllDirectories)); } } string rootPath = Path.GetDirectoryName(fileDrops[0]); ProgresshWindow dlg = new ProgresshWindow() { Owner = Window.GetWindow(this) }; dlg.Show(); Task.Run(() => { try { int num = files.Count; int index = 0; foreach (string file in files) { if (dlg.IsCancelPendíng) { break; } Invoke(() => dlg.Update((double)(index++) / num, file)); // for updating progress windows Thread.Sleep(1); // do push Invoke(() => { string relPath = GetRelPath(file, rootPath); if (File.Exists(file)) { using (FileStream stream = File.OpenRead(file)) { this.SelectedItem.Content.Push(stream, relPath); } } else if (Directory.Exists(file)) { this.SelectedItem.Content.CreateFolder(relPath); } }); } Invoke(() => { dlg.Update(1.0); // let window stay for 2 sec to prevent flickering for small files Thread.Sleep(2000); dlg.Close(); this.selectedItem.Refresh(true); }); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }); } e.Handled = true; }