Wednesday, January 6, 2010

Using Drag and Drop in a Silverlight 4 Application

Today I was working through the excellent Image Browser Lab lab to teach myself some of the newer features in Silverlight 4.  If you haven’t tried that lab as yet, you should, it shows you how to build a really cool Image browsing application which supports moving, resizing, and rotating images on a canvas.  It also shows you how to enable the scenario where a user can drag pictures from their hard drive and into the Silverlight application.  Very cool stuff!  Here’s a picture of the page in action:

image

As you will notice, in this tutorial, it shows you how to add the yellow drag handles that you see on the middle photo so that you can resize and move the images around.  And as also mentioned, you can drag images in off of your own hard drive.  If you have 5 minutes to spare, here is a link to a video by Jesse Liberty which shows how simple it is to get Drag and Drop working.

What happens if you cannot get Drag and Drop to work in your Silverlight application?

OK, call me a simpleton, but this got me today and so I’m going to put it out there to hopefully save some other poor sucker the hour it took me to work out what was going on.  Emboldened after having worked through this exercise, I decided to implement some Drag and Drop goodness in one of my own applications.  I added the few lines of mark up and code that are required to get things working, ran it up with F5, and nothing!  Zip!  Drag and Drop was not working for me.

The long of the short of it is that I had started the instance of Visual Studio in elevated mode.  What this meant was that Windows was protecting me by not allowing me to drag files from my Windows Explorer instance (which was not elevated) into my IE process (which was).

So after about an hour of scratching my head, it turned out to be a simple fix.  And now I have drag and drop functionality in my own application! Hot

1 comment:

  1. Sometimes I hate UAC... Now the users of your app will also have to know about that? How're they going to find out? Do they have to read your blog, disable UAC or call tech support?

    ReplyDelete