Skip to content

Commit 1073288

Browse files
committed
Enable drop for DataGrid
1 parent 5cf6072 commit 1073288

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

Files UWP/GenericFileBrowser.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
xmlns:local2="using:Files.Filesystem"
1313
xmlns:local3="using:Files.Interacts"
1414
Name="GenericItemView"
15-
mc:Ignorable="d" IsRightTapEnabled="True" RightTapped="GenericItemView_RightTapped" PointerReleased="GenericItemView_PointerReleased">
15+
mc:Ignorable="d" IsRightTapEnabled="True" RightTapped="GenericItemView_RightTapped" PointerReleased="GenericItemView_PointerReleased">
1616
<Page.Resources>
1717
<Style x:Key="TextBoxStyleForPathBar" TargetType="TextBox">
1818
<Setter Property="Foreground" Value="{ThemeResource DefaultTextForegroundThemeBrush}"/>
@@ -266,7 +266,7 @@
266266

267267

268268

269-
<controls:DataGrid ContextRequested="AllView_ContextRequested" SelectionChanged="AllView_SelectionChanged" Margin="24,0,0,0" Grid.Row="3" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local:App.ViewModel.FilesAndFolders}" HorizontalAlignment="Left">
269+
<controls:DataGrid AllowDrop="True" Drop="AllView_DropAsync" DragLeave="AllView_DragLeave" DragStarting="AllView_DragStarting" ContextRequested="AllView_ContextRequested" SelectionChanged="AllView_SelectionChanged" Margin="24,0,0,0" Grid.Row="3" CellEditEnded="AllView_CellEditEnded" FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" AutoGenerateColumns="False" CanDrag="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local:App.ViewModel.FilesAndFolders}" HorizontalAlignment="Left">
270270

271271
<controls:DataGrid.ColumnHeaderStyle>
272272
<Style TargetType="controlsprimitives:DataGridColumnHeader">

Files UWP/GenericFileBrowser.xaml.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using Windows.UI.Popups;
2222
using System.IO;
2323
using Windows.UI.Xaml.Controls.Primitives;
24+
using Windows.ApplicationModel.DataTransfer.DragDrop.Core;
25+
using System.Collections.Generic;
2426

2527
namespace Files
2628
{
@@ -236,16 +238,17 @@ private async void AllView_DropAsync(object sender, DragEventArgs e)
236238
{
237239
if (e.DataView.Contains(StandardDataFormats.StorageItems))
238240
{
239-
var items = await e.DataView.GetStorageItemsAsync();
240-
if(items.Count() == 1)
241-
{
242-
DataPackage data = new DataPackage();
243-
foreach(IStorageItem storageItem in items)
241+
foreach (IStorageItem item in await e.DataView.GetStorageItemsAsync())
244242
{
245-
var itemPath = storageItem.Path;
246-
247-
}
248-
}
243+
if (item.IsOfType(StorageItemTypes.Folder))
244+
{
245+
Interaction.CloneDirectoryAsync((item as StorageFolder).Path, App.ViewModel.Universal.path, (item as StorageFolder).DisplayName);
246+
}
247+
else
248+
{
249+
await (item as StorageFile).CopyAsync(await StorageFolder.GetFolderFromPathAsync(App.ViewModel.Universal.path));
250+
}
251+
}
249252
}
250253
}
251254

@@ -477,6 +480,16 @@ private void AllView_ContextRequested(UIElement sender, ContextRequestedEventArg
477480
{
478481

479482
}
483+
484+
private void AllView_DragStarting(UIElement sender, DragStartingEventArgs args)
485+
{
486+
args.DragUI.SetContentFromDataPackage();
487+
}
488+
489+
private void AllView_DragLeave(object sender, DragEventArgs e)
490+
{
491+
492+
}
480493
}
481494

482495
public class EmptyFolderTextState : INotifyPropertyChanged

0 commit comments

Comments
 (0)