dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.1k stars 1.17k forks source link

WPF drop is not working #3772

Open vsfeedback opened 4 years ago

vsfeedback commented 4 years ago

This issue has been moved from a ticket on Developer Community.


I am using Windows 10 latest version, project is in WPF .NET Framework 4.8, latest visual studio.

To make it super simple I've created a brand new WPF project. Event handlers are not called. This is the code:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="https://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" AllowDrop="True">
    <Grid Focusable="True" AllowDrop="True" Drop="Grid_Drop" DragOver="Grid_DragOver" DragEnter="Grid_DragEnter" PreviewDrop="Grid_PreviewDrop" PreviewDragEnter="Grid_PreviewDragEnter" PreviewDragOver="Grid_PreviewDragOver" Background="Transparent">

    </Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Grid_Drop(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;

        }

        private void Grid_DragOver(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
        }

        private void Grid_DragEnter(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
        }

        private void Grid_PreviewDrop(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
        }

        private void Grid_PreviewDragEnter(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
        }

        private void Grid_PreviewDragOver(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
        }
    }
}

What should I do next?

--- ### Original Comments #### Feedback Bot on 4/1/2020, 10:40 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

#### Feedback Bot on 5/8/2020, 03:27 PM: I have detected that for the last 35 days, this issue didn't have much product team activity and a very small amount of new votes or comments. Based on this, its severity, and affected area, it’s my experience that this issue is very unlikely to be fixed. --- ### Original Solutions #### Hrvoje Batrnek solved on 5/8/2020, 04:20 PM, 0 votes:

"I have detected that for the last 35 days..."

Your detection has an error. I am waiting for the response and there was no response.

rlcarrierscsharp commented 1 year ago

I am also unable to get drag and drop to work. I'm simply trying to drag a text file onto the WPF application (testing with a fresh project and a simple window) and the cursor always shows a red cross, even when copying / pasting examples from the MSDN Drag and Drop WPF documentation.

miloush commented 1 year ago

@rlcarrierscsharp can you include a sample project to try your scenario on?