• Silverlight 4 - Drag and drop images on a Silverlight application

    One of the great new features of Silverlight 4 is drag-drop. This makes it possible to drag files from your OS onto the Silverlight application.   In this tutorial we’ll create a ListBox and make it possible to drop images from the desktop onto the application. The images will then appear in the ListBox.  

    First steps

    First of all we’ll create a “normal” Silverlight 4 App + Website using Visual Studio 2010 or Expression Blend. Next we need a ListBox to show the images when they are dropped on it. Make sure your XAML looks similar to this:
    <UserControl  x:Class="DragDrop.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="328" d:DesignWidth="514">  <Grid  x:Name="LayoutRoot" Background="White">  <ListBox  Height="Auto" HorizontalAlignment="Left" Name="listBox1" VerticalAlignment="Stretch" Width="200"  />  </Grid>  </UserControl>  

    Hooking it up

    Next step is to create an eventhandler for the drop event. But first we need to make sure that it is allowed to drop objects onto the ListBox. This is done by setting the AllowDrop property of the ListBox to true. So with the addition of that ...

    Full story

    Comments (1416)

  • Silverlight 4 – Using the webcam

    Yesterday the beta release of Silverlight 4 was announced. Of course I couldn’t resist to get started with one of the items on my personal wish list (and on lots of other peoples wish list as well).   Using the webcam in Silverlight 4 turned out to be a quite easy process. I only needed about 8 lines to get it started. A few lines more and I have an application which starts and stops the webcam with the click of a button.  

    Create the controls

    First thing I did was create the controls in xaml using the new designer in Visual Studio 2010. I created a Grid to show the video in (I’ll explain later on why I used a Grid instead of the expected MediaElement) and a button for starting and stopping it.  

    Huh?! No Stream?

    As I mentioned before we’ll be using a Grid to display the video in. Why wouldn’t you use a MediaElement? The reason for that is that, as far as I have found out until now, no Stream output for the videocapturing devices available. This probably has something to do with the difficulty to control the videocapturing devices and with the ...

    Full story

    Comments (0)