In this article we see the code to drag and drop an element from one panel to another in Silverlight.
In this application we see the code to drag and drop an element from one panel to another.Here we use two Stack Panels. One is the containing panel and the other is the dropping panel.There are four items in the lower panel. We can drag and drop or a single click can also move objects from one panel to the other.Now let us see how the code can be:XAMLIn the designer we have The Visual tree of control is as in the figure below. The scroll bar can be used as the requirements and number of items in the Item slider.The code is:<Canvas x:Name="LayoutRoot" Background="White" Height="534" Margin="0,0,-200,0"
<StackPanel x:Name="itemSlider" RenderTransformOrigin="0.5,0.5" Orientation="Horizontal"
HorizontalAlignment="Left">
<StackPanel.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</StackPanel.RenderTransform>
<Image Source="images/Creek.jpg" Stretch="Fill" x:Name="item2" HorizontalAlignment="Left"
Tag="draggable" VerticalAlignment="Top"d:LayoutOverrides="HorizontalMargin"/>
<Image HorizontalAlignment="Left" x:Name="item1" Source="images/Autumn-Leaves.jpg" Stretch="Fill" Tag="draggable" VerticalAlignment="Top"/>
<Image Source="Images/Desert-Landscape.jpg" Stretch="Fill" x:Name="item3" Margin="10,0,0,0"
HorizontalAlignment="Left" Tag="draggable"VerticalAlignment="Top"/>
<Image Source="images/Forest-Flowers.jpg" Stretch="Fill" x:Name="item4" Margin="10,0,0,0"
</StackPanel>
<StackPanel x:Name="DragToStackPanel" HorizontalAlignment="Left" Background="#FFEED6D6"
Height="300" Width="830" Orientation="Horizontal"/>
</Canvas>
</Canvas>Now you have the look of the application.Next is the real interesting part the code behind that makes the whole thing possible.Note: Please note that all the draggable controls are tagged as "draggable"Code BehindThe methods to be noted in each event
LINQ Quick Reference with C#