在 Windows 应用程序中拖放项目并获取项目的标准数据格式

Drag and Drop items in Windows application and Get the StandardDataFormats of the items

我正在开发一个 windows 应用程序,我在其中拖放了一个项目(文件、文件夹、URL、文本等),然后我想检查拖放的项目 StandardDataFormats [StorageItems 或 WebLink 或文本]。

这是我的实现思路:

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
    }
}

此实现适用于文件、文件+文件夹和文本,但当我删除任何 web-link 时,所有 if 语句都会执行。 我如何检查 StandardDataFormats 以便当我删除 web link 时只执行我的第二个 if 语句。

Drag and Drop items in Windows application and Get the StandardDataFormats of the items

问题是掉落的项目是 WebLink 以及 Internet 快捷方式。所以它会执行第二条语句。对于这种场景,建议使用if-else语句,将WebLink放在第一个语句中,如果为真,则跳过后面的语句。

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

}