2009-09-03 142 views

回答

3

我看着這個最近,基於從Silverlight的MVP在下面的線程後,Silverlight 3中不支持文件系統拖放下降。

http://betaforums.silverlight.net/forums/t/117317.aspx?PageIndex=1

看來的Silverlight 4現在支持這一點:

http://www.silverlight.net/learn/videos/silverlight-4-beta-videos/silverlight-controls-drop-targets/

+0

Bah,我浪費了整個騎自行車的家計劃一個很酷的應用程序。謝謝 – stimms

+0

Silverlight 4中現在提供了此功能:http://www.silverlight.net/learn/videos/silverlight-4-beta-videos/silverlight-controls-drop-targets/ –

0

您可以將桌面從在Silverlight 4和上述申請下降。選中silverlight項目屬性中的「Require Elevated permissions」,並使用silverlight datagrid的drop事件,可以處理Silverlight數據網格中桌面的拖放操作。

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;在數據網格的xaml中。從DragEventArgs中提取信息作爲FileInfo對象。 我不知道這與Silverlight 3應用程序的工作