
Что я делаю не так? Нужно ли мне активировать какие-то возможности?
Как ни странно, это работает, если я перетаскиваю файл из элементов Недавние в разделе «Пуск» Проводника:

Но все остальные места, например рабочий стол, не работают.
MainWindow.xaml:
Код: Выделить всё
Код: Выделить всё
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System;
using System.IO;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
namespace FileDragDropApp
{
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}
private async void Grid_Drop(object sender, DragEventArgs e)
{
// Check if the dropped data contains files
if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
// Get the file(s) from the DataPackage
var items = await e.DataView.GetStorageItemsAsync();
if (items.Count > 0)
{
// Display the first file's name
var storageFile = items[0] as StorageFile;
if (storageFile != null)
{
FileNameTextBlock.Text = $"File: {storageFile.Name}";
}
}
}
}
private void Grid_DragOver(object sender, DragEventArgs e)
{
// This is not being called
e.AcceptedOperation = DataPackageOperation.Copy;
}
}
}
Я также протестировал DragEnter. Тот же результат.
Код: Выделить всё
Код: Выделить всё
private void Grid_DragEnter(object sender, DragEventArgs e)
{
Debug.WriteLine("Grid_DragEnter");
}
Код: Выделить всё
Grid_DragEnter
Проверено на:
Выпуск Windows 11 Pro
Версия Круглосуточно
Сборка ОС 26100.2161
Используйте Windows Feature Experience Pack 1000.26100.32.0
Microsoft.Windows.SDK .BuildTools 10.0.26100.1742
Microsoft.WindowsAppSDK 1.6.240923002
Подробнее здесь: https://stackoverflow.com/questions/791 ... app-window