NoWar
NoWar

Reputation: 37633

DragEnter event issue

I just do drag and drop ZIP file over WPF ListBox.

And after that I am facing that ZIP file is opened. WHY? I didn't asked to open it at all.

Here is my code.

private void lbPackageList_DragEnter(object sender, DragEventArgs e)
{
    bool isCorrect = true;

    if (e.Data.GetDataPresent(DataFormats.FileDrop, true) == true)
    {
        string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, true);
        foreach (string filename in filenames)
        {
            if (File.Exists(filename) == false)
            {
               isCorrect = false;
               break;
             }
            FileInfo info = new FileInfo(filename);
           if (info.Extension == ".zip") // It's correct
           {
              // OK  
           }
           else
           {
               isCorrect = false;
               break;
           }

     }
   }
   if (isCorrect == true)
        e.Effects = DragDropEffects.All;
   else
         e.Effects = DragDropEffects.None;
            e.Handled = true;
}

Any clues why it is happening? And how do We can stop it?

Upvotes: 0

Views: 179

Answers (1)

NoWar
NoWar

Reputation: 37633

WOW

I found the answer

It should be like that

string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, false);

Upvotes: 1

Related Questions