Move and delete files

This commit is contained in:
2026-02-16 13:08:23 +09:00
parent 0da7361c9f
commit 1d2e1b9f3e
5 changed files with 128 additions and 11 deletions
+34
View File
@@ -0,0 +1,34 @@
using System.Collections.ObjectModel;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.VisualTree;
using Avalonia.Xaml.Interactions.DragAndDrop;
using ReceiptPDFBuilder.Models;
using ReceiptPDFBuilder.ViewModels;
namespace ReceiptPDFBuilder.Helpers;
class DataGridDropHandler : BaseDataGridDropHandler<ReportFile>
{
// https://wieslawsoltes.github.io/Xaml.Behaviors/articles/drag-and-drop-datagrid/datagrid-drag-and-drop-overview.html
// ...that page's code basically doesn't work in the way you'd expect. so just use the source code sample's code.
protected override bool Validate(DataGrid dg, DragEventArgs e, object? sourceContext, object? targetContext, bool execute)
{
if (sourceContext is not ReportFile sourceItem
|| targetContext is not MainViewModel vm
|| dg.GetVisualAt(e.GetPosition(dg)) is not Control targetControl
|| targetControl.DataContext is not ReportFile targetItem)
{
return false;
}
var items = dg.ItemsSource as ObservableCollection<ReportFile>;
return RunDropAction(dg, e, execute, sourceItem, targetItem, items?? []);
}
protected override ReportFile MakeCopy(ObservableCollection<ReportFile> parentCollection, ReportFile item)
{
// Return a clone of the item if you support Copy operations
return new ReportFile { };
}
}