Vectorlight News

  • Chat App Converted to HTML and JQuery
    Sep 08, 2011

    Converted from Silverlight to HTML and Javascript/JQuery is the Vectorlight Chat App. Login using your Vectorlight password to chat using your username and avatar.

  • HTML5 iPhone,Android Big Guns Tower Defense
    Jul 02, 2011

    Big Guns has made the leap from Windows Phone 7 (XNA) to HTML5 so you can now play it on your iPhone, Android and other HTML5 compatible devices.

  • HTML5 Games - Word Poppers and Batty
    Jun 04, 2011

    As the take-up of HTML5 quickens (74% of users currently have a browser capable of HTML5 Canvas) we present two more games for both your browser and mobile.

  • Big Guns Tower Defense on Windows Phone 7
    May 06, 2011

    Coming soon to Windows Phone 7 is an XNA port of the popular Vectorlight tower defense game Super Tower Defense. Whilst retaining many of the graphical and gameplay features of the original Silverlight game.

  • Wakacube WP7 Update
    Apr 26, 2011

    Released to the Windows Phone 7 marketplace today is Version 1.1 of Wakacube the 3D physics game of skill. Included in the update are more levels (30 in total) and new mode Wakatime which generates random crate structures to keep players entertained long after the levels have been completed.

  • Home Page News

Desktop Drag and Drop Files

With Silverlight 4 is the new Drop event which is present on all elements derived from UIElement.  With this simple example we will display a Grey area which you can drop a file onto.


<UserControl x:Class="DesktopDragandDrop.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="200" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" AllowDrop="True" Drop="LayoutRoot_Drop" Background="#f0f0f0">
            <TextBlock Text="Drop some files here!" FontSize="24" TextAlignment="Center" VerticalAlignment="Center" />
        </Grid>
        <TextBlock x:Name="output" Grid.Row="1" />
    </Grid>
</UserControl>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Text;

namespace DesktopDragandDrop
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void LayoutRoot_Drop(object sender, DragEventArgs e)
        {
            FileInfo[] files = ( FileInfo[])e.Data.GetData(System.Windows.DataFormats.FileDrop);
            StringBuilder content = new StringBuilder();

            foreach (FileInfo file in files)
            {
                content.Append(file.Name);
                content.Append(Environment.NewLine);
            }

            output.Text = content.ToString();
        }
    }
}


As you can see in the LayoutRoot_Drop event handler we are provided with a data object passed in via the event args object.  When dropping files onto your Silverlight application this will be an array of FileInfo objects.

The FileInfo object contains basic file information such as its name and extension and size.  To be able to read the file you will need to be running your application Out of Browser.

Your Comments

MarkSilver posted

Hi,



I like this drag and drop with files..the only thing is that i can`t get it work on my machine


I've just made a simple silverlight application copy and paste your code, and run it...it runs ok but when i drag and drop a file nothing happens...is this because of a setting in ie9 ? or in vs 2010?



Hope some body can help solving this...i`m new in the silverlight flow..



Best regards,



Mark


Mark posted

It looks cool overhere, but when i try to run this code in vs2010 i can`t drop a file in the webform..



I've made a simple silverlight 4 application copy and past the code you have written..and then run it on a windows 7 machine..ie9



Hope you can help with running this code?


Best regards,



Mark


Ron Richins posted

Let us compare, drag n' drop.  Asp.NET, how (stateless)?



Silverlight (stateful), client side/server side events and commands.



Personally, I do not care where there are stored, as long as they are available the next time from this visitor, I can improve the response time for that individual.



Cory Seaman,


Just my opinion, but you are placing far too much emphasis on accessing an individuals personal computer.  I love the fact that I can now utilized the cpu, video, and memory of the client personal computer (this includes: local cacheing, multi-core/parralell processing, local storage, and async push of "MY" everything).



The fact that, I do not have access to anything beyond, ("My Documents") should be construde as a positive.  The operating system, has safe guards when launching a program.  If the operating system has not seen this program before, the "Operating System and/or the ant-virus will catch it".



In both cases, your computer will ask you if this is allowed.



From me to you and everyone.



When in doubt, cancel.



If you recognize the requestor, and say okay.  Absolutely, anything that you were not expecting to see, should be deemed a threat. Close immediately, If it will not close, immediately hold your finger on the power button, until every light is off of your computer.  



When you restart your computer, you will get a warning message:



Safe (always safe, however, unable to access the internet).



Normal (ignores the loss of power, check point restart, and restarts as normal).



Ron


parv posted

I Liked it


Matt Eland posted

Seems to work fine for any random folder on my machine (though attempting to get directory information generates security exceptions).



I've heard this doesn't work as well on Macs. Is this true?


Cory Seaman posted

The functionality of the drag and drop feature is still, unfortunately, very limited, it would seem (through the RC version)...even when running out of browser you're still limited to a user's special folders like "My Documents".  I wrote a sample app to .zip files, and the only ones the app has genuine access to are those dragged from the allowed handful of special folders.  I think there's going to be some frustration when the meaning of this starts to become apparent to developers--drag and drop is such a promising feature!


 

Post your Comments

Rate this: 

1 Star 2 Star 3 Star 4 Star 5 Star
17 Ratings / 3.4 Average

Tweets

Silverlight Controls

  • Rich TextBox

    Create and edit rich content with this slick and expandable Rich TextBox...

  • TreeView

    This easy to use TreeView comes with drag and drop, sorting, searching and much more...

  • Context Menu

    You too can have cool popup context menus in your Silverlight applications...

  • Resizable Dialog

    Draggable and resizable popup dialogs are what serious Silverlight developers need...

  • Spell Checker

    Real-time spell checking in Silverlight? We did it first here...