Loading a drag and drop file in Silverlight 4?

I am working on rewriting a WinForms application in Silverlight. One use case in the WinForms application allows users to drag and drop TIFF images (from faxes) from Outlook directly onto the โ€œattach image or fax to this caseโ€ control in the WinForms application. Is there a Silverlight 4 control that allows you to use the same features? It is important to understand that saving a file to the local file system, and then selecting and downloading a file with a standard download control does not meet the business requirements set forth in the project.

+3
source share
3 answers

Silverlight 4 supports dragging and dropping files from the file system to any UIElement. Watch the blog

However, I donโ€™t know whether this will work with drag and drop initiated in Outlook. I suggest you get a sample from this blog and create a small test application to see if you can drag and drop attachments.

Of course, you still have work to decode TIFF into a bitmap that Silverlight can use.

+2
source

( , Silverlight - "" . , WPF Silverlight, , Windows).

- Silverlight,

this.Drop += new DragEventHandler(MainPage_Drop);

void MainPage_Drop(object sender, DragEventArgs e)
{
    IDataObject drop = e.Data;

    if (drop.GetDataPresent(System.Windows.DataFormats.FileDrop))
    {
        FileInfo[] files = (FileInfo[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
        foreach (FileInfo file in files)
        {
          // do something with each file here
        }
    }
}

- , . TIFF, , - Stackoverflow, .

+1

You can drag and drop from the desktop in the silverlight application. I implemented this in our project. Check the "Require elevated permissions" checkbox in the properties of the Silverlight project and using the drop event for the Silverlight datagrid, you can handle drag and drop from the desktop to the datagrid 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; in xaml for datagrid. Extracts information from DragEventArgs as a FileInfo object.

0
source

Source: https://habr.com/ru/post/1744605/


All Articles