Reputation: 355
I am developing an windows application where I drag and dropped an items(File, Folder, URL, Text and etc.) then I want to check the dropped item StandardDataFormats [StorageItems or WebLink or Text].
Here is my implementation idea :
void DroppedItems(object sender, DragEventArgs items)
{
if (items.DataView.Contains(StandardDataFormats.StorageItems))
{
//Do something
}
if (items.DataView.Contains(StandardDataFormats.WebLink))
{
//Do something
}
if (items.DataView.Contains(StandardDataFormats.Text))
{
// Do something
}
}
This implementation works fine for File, File+Folder and Text but when I dropped any web-link all the if statement is executed. How can I check the StandardDataFormats so that when I dropped web link only my second if statement is executed.
Upvotes: 1
Views: 193
Reputation: 32775
Drag and Drop items in Windows application and Get the StandardDataFormats of the items
The problem is that the dropped item is WebLink as well as internet shortcut. so it will execute the second statement. for this scenario, we suggest you use if-else statement, and place WebLink in the first statement, if it is true, it will skip the following statement.
if (e.DataView.Contains(StandardDataFormats.WebLink))
{
//Do something
}
else if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
//Do something
}
else if (e.DataView.Contains(StandardDataFormats.Text))
{
// Do something
}
Upvotes: 1