I'm really trying to get a simple drag and drop pattern that works in Silverlight 4.
Here is what I have:
Xaml
<UserControl x:Class="TestDragDrop.MainPage" Width="350" Height="200"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="White">
<Rectangle Margin="50,50,200,50" Fill="Orange" MouseLeftButtonDown="r1_MouseLeftButtonDown" />
<Rectangle Margin="200,50,50,50" Fill="Orange" AllowDrop="true" Drop="r2_Drop" />
</Grid>
</UserControl>
Code-behind
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void r1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragDrop.DoDragDrop((Rectangle)sender, "test data", DragDropEffects.All, DragDropKeyStates.LeftMouseButton);
}
private void r2_Drop(object sender, System.Windows.DragEventArgs e)
{
MessageBox.Show("Drop: " + e.Data.ToString());
}
}
The event DragDrop.DragDropCompletedfires, however, the sender parameter is always zero, and the event arguments do not help me learn more about the event.
I also tried using a custom control that implements IAcceptDrop with no luck.
Also, when I start the drag and drop operation, I have no visual feedback that something is happening (without changing the cursor or anything else). Something is wrong?
All the samples I found use DragDropTargets. Is my only way to implement a DragDropTarget for the specific type of controls that I want to use?