diff --git a/src/Files.App/BaseLayout.cs b/src/Files.App/BaseLayout.cs index 837c365c529f..4b42aa071ecb 100644 --- a/src/Files.App/BaseLayout.cs +++ b/src/Files.App/BaseLayout.cs @@ -26,10 +26,13 @@ using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; +using System.IO; using System.Linq; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices.ComTypes; using System.Threading; using System.Threading.Tasks; +using Vanara.PInvoke; using Windows.ApplicationModel.DataTransfer; using Windows.ApplicationModel.DataTransfer.DragDrop; using Windows.Foundation; @@ -37,6 +40,7 @@ using Windows.Storage; using Windows.System; using static Files.App.Helpers.PathNormalization; +using VA = Vanara.Windows.Shell; using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer; using SortDirection = Files.Shared.Enums.SortDirection; @@ -875,11 +879,27 @@ protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceive protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { SelectedItems!.AddRange(e.Items.OfType()); + try { - // Only support IStorageItem capable paths - var itemList = e.Items.OfType().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x)); - e.Data.SetStorageItems(itemList, false); + var shellItemList = e.Items.OfType().Select(x => new VA.ShellItem(x.ItemPath)).ToArray(); + if (shellItemList[0].FileSystemPath is not null) + { + var iddo = shellItemList[0].Parent.GetChildrenUIObjects(HWND.NULL, shellItemList); + shellItemList.ForEach(x => x.Dispose()); + var format = System.Windows.Forms.DataFormats.GetFormat("Shell IDList Array"); + if (iddo.TryGetData((uint)format.Id, out var data)) + { + var mem = new MemoryStream(data).AsRandomAccessStream(); + e.Data.SetData(format.Name, mem); + } + } + else + { + // Only support IStorageItem capable paths + var storageItemList = e.Items.OfType().Where(x => !(x.IsHiddenItem && x.IsLinkItem && x.IsRecycleBinItem && x.IsShortcut)).Select(x => VirtualStorageItem.FromListedItem(x)); + e.Data.SetStorageItems(storageItemList, false); + } } catch (Exception) {