[英]Silverlight and desktop drag and drop
Is there, in silverlight, the ability to drag and drop files from the desktop into the browser? 在Silverlight中,是否可以将文件从桌面拖放到浏览器中? I seem to remember seeing something about it being a feature in silverlight 3.
我似乎还记得我在Silverlight 3中看到过一些功能。
I looked into this recently, and based on a post from a Silverlight MVP in the following thread, Silverlight 3 does not support file system drag and drop. 我最近对此进行了调查,并基于以下线程中Silverlight MVP的帖子,Silverlight 3 不支持文件系统拖放。
http://betaforums.silverlight.net/forums/t/117317.aspx?PageIndex=1 http://betaforums.silverlight.net/forums/t/117317.aspx?PageIndex=1
It appears Silverlight 4 now supports this: 看来Silverlight 4现在支持此功能:
http://www.silverlight.net/learn/videos/silverlight-4-beta-videos/silverlight-controls-drop-targets/ http://www.silverlight.net/learn/videos/silverlight-4-beta-videos/silverlight-controls-drop-targets/
You can Drag and drop from desktop in a silverlight 4 and above application. 您可以在Silverlight 4及更高版本的应用程序中从桌面拖放。 Check "Require Elevated permissions" in silverlight project properties and using drop event of silverlight datagrid one can handle the drag and drop from desktop in a silverlight datagrid.
在silverlight项目属性中选中“需要提升的权限”,使用silverlight datagrid的drop事件,可以在silverlight datagrid中处理从桌面的拖放。
private void DocumentsDrop(object sender, DragEventArgs e)
{
e.Handled = true;
var point = e.GetPosition(null);
var dataGridRow = ExtractDataGridRow(point);
if(dataGridRow !=null)
{.....
}
var droppedItems = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];
if (droppedItems != null)
{
var droppedDocumentsList = new List<FileInfo>();
foreach (var droppedItem in droppedItems)
{
if ((droppedItem.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
{
var directory = new DirectoryInfo(droppedItem.FullName);
droppedDocumentsList.AddRange(directory.EnumerateFiles("*", SearchOption.AllDirectories));
}
else
{
droppedDocumentsList.Add(droppedItem);
}
}
if (droppedDocumentsList.Any())
{
ProcessFiles(droppedDocumentsList);
}
else
{
DisplayErrorMessage("The selected folder is empty.");
}
}
}
Set AllowDrop =true; 设置AllowDrop = true; in xaml for the datagrid.
在xaml中表示datagrid。 From the DragEventArgs extract the information as FileInfo Object.
从DragEventArgs中提取信息作为FileInfo对象。 I am not sure about this working with Silverlight 3 application
我不确定与此Silverlight 3应用程序一起使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.