.

Allowing drag and drop in WPF

This will allow you to do drag and drop in WPF:

public THIS_IS_THE_WPF_FORM_CONSTRUCTOR()
{
    InitializeComponent();

    AllowDrop = true;

    DragEnter += Form_DragEnter;
    Drop += Form_DragDrop;
}

private void Form_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.Html))
        e.Effects = DragDropEffects.Copy;
    else
        e.Effects = DragDropEffects.None;
    e.Handled = true;
}

private void Form_DragDrop(object sender, DragEventArgs e)
{
    if (!e.Data.GetDataPresent(DataFormats.Html))
        return;

    var data = e.Data.GetData(DataFormats.Text, false);
    var url = (string)data;

    MessageBox.Show(url);
}

you can also try this example:

 

<Window x:Class="FileManager.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <DockPanel LastChildFill="True">
        <Button Content="Dock=Top" DockPanel.Dock="Top"/>
        <Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/>
        <StackPanel Orientation="Horizontal"  DockPanel.Dock="Left">
            <ListView Width="auto">
                <ListView.View>
                    <GridView>
                        <GridView.ColumnHeaderContainerStyle>
                            <Style>
                                <Setter Property="FrameworkElement.Visibility" Value="Collapsed"/>
                            </Style>
                        </GridView.ColumnHeaderContainerStyle>
                        <GridView.Columns>

                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
            <TreeView HorizontalAlignment="Left" Height="auto"  VerticalAlignment="Top" Width="100">

            </TreeView>
        </StackPanel>
        <ListBox Width="200px" DockPanel.Dock="Right" Name="dropbox" DragEnter="Dropbox_OnDragEnter" Drop="Dropbox_OnDrop" AllowDrop="True">

        </ListBox>
        <Button Content="LastChildFill=True"/>
    </DockPanel>
</Window>

with this code:

using System;
using System.Collections.Generic;
using System.IO;
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 FileManager
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Dropbox_OnDragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
                e.Effects = DragDropEffects.All;
            else
                e.Effects = DragDropEffects.None;
        }

        private void Dropbox_OnDrop(object sender, DragEventArgs e)
        {
            List<string> filepaths = new List<string>();
            List<string> folderpaths = new List<string>();
            foreach (var s in (string[])e.Data.GetData(DataFormats.FileDrop, false))
            {
                if (Directory.Exists(s))
                {
                    //Add files from folder
                    folderpaths.Add(s);
                    //folderpaths.AddRange(Directory.GetFiles(s));
                }
                else if (File.Exists(s))
                {
                    //Add filepath
                    filepaths.Add(s);
                }
            }
        }
    }
}

What's your thoughts on this?

*

Protected by WP Anti Spam