Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF,如何检查光标是否有文件?_C#_Wpf - Fatal编程技术网

C# WPF,如何检查光标是否有文件?

C# WPF,如何检查光标是否有文件?,c#,wpf,C#,Wpf,我想知道在Windows环境中,光标是如何在桌面上保持图标并获取该图标的状态的 例如,当我在桌面上抓取一个文件并拖动它时,我想知道该文件的属性,例如它的名称和扩展名。WPF控件可以使用EventHandler DragEnter来检查这一点 <ListView x:Name="DropList" Drop="DropList_Drop" DragEnter="DropList_DragEnter" AllowDrop="Tr

我想知道在Windows环境中,光标是如何在桌面上保持图标并获取该图标的状态的


例如,当我在桌面上抓取一个文件并拖动它时,我想知道该文件的属性,例如它的名称和扩展名。

WPF控件可以使用EventHandler DragEnter来检查这一点

<ListView x:Name="DropList" 
          Drop="DropList_Drop" 
          DragEnter="DropList_DragEnter" 
          AllowDrop="True" />     


private void DropList_DragEnter(object sender, DragEventArgs e)
{
    if (!e.Data.GetDataPresent(DataFormats.FileDrop)) // checks for File
    {
        e.Effects = DragDropEffects.None;
    }
}
private void DropList_Drop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
        // loop through files..
    }
}