Silverlight 4 drag and drop support

Source: Internet
Author: User

One of the new features of Silverlight 4 is drag-and-drop support. It is easy to use.

You can manage all drag-and-drop operations with three events.

1: // drag? Put? After I complete my tasks? Parts t
2:  media.Drop += doDrop;
3: // drag? Put? Why? Parts t
4:  media.DragEnter += doDragEnter;
5: // drag? Put? Jieáshu? Hour + thing? Parts t
6:  media.DragLeave += doDragLeave;
7:  

In the drop event. You can also drag and drop E. Data to the Silverlight file set and use the following code to get the file set:

1:  IDataObject dataObject = e.Data as IDataObject;
2:  FileInfo[] files = dataObject.GetData( DataFormats.FileDrop ) as FileInfo[];
3:  

After obtaining files, I can use recursion to list all files:

1:  foreach ( FileInfo file in files )
2:  {}
3:  

After obtaining fileinfo, we can drag and drop the extension of the file to perform corresponding operations. The following example shows how to drag and drop a XAML file and convert it into a uielement:

 1:  if ( file.Extension.Equals( ".xaml" ) )
 2:  {
 3:    string contents;
 4:    using ( Stream stream = file.OpenRead() )
 5:    {
 6:      using ( StreamReader reader = new StreamReader( stream ) )
 7:      {
 8:        contents = reader.ReadToEnd();
 9:      }
10:    }
11:    UIElement uiElement = XamlReader.Load( contents ) as UIElement;
12:    this.xamlViewer.Children.Add( uiElement );
13:  }
14:  

The operation is so simple!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.