Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Drag and drop onto custom grid
1 replies. Latest Post by Min-Hong Tang - MSFT on November 26, 2009.
(0)
gnop
Member
8 points
27 Posts
11-23-2009 2:42 PM |
Hi, i was wondering if it was possible to be able to drag and drop from the listboxdragdroptarget control onto a custom grid that i generated manually(not a datagrid), is there a way to make like a drop zone where if it is dropped there it will pass the values from the listbox item being dragged from?
Thanks
Min-Hong...
Contributor
3375 points
377 Posts
11-26-2009 12:48 AM |
Hi,
It is possible,you can use a code block like this:
<toolkit:ListBoxDragDropTarget ItemDragStarting="ListBoxDragDropTarget_ItemDragStarting" ItemDroppedOnTarget="ListBoxDragDropTarget_ItemDroppedOnTarget" > <ListBox x:Name="lb"></ListBox> </toolkit:ListBoxDragDropTarget> <Grid Background="Red" Width="100" Height="200" MouseLeftButtonUp="Grid_MouseLeftButtonUp"> <TextBox x:Name="tb" Text="Nothing" Width="100" Height="20"></TextBox> </Grid>
CodeBehind
private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (o != null) { tb.Text = ((Person)o).Name; //Person is my own class has two properties(Age and Name) o = null; } } private object o; private void ListBoxDragDropTarget_ItemDragStarting(object sender, ItemDragEventArgs<ListBox> e) { o = e.DragSource.SelectedItem; } private void ListBoxDragDropTarget_ItemDroppedOnTarget(object sender, ItemDragEventArgs<ListBox> e) { o = null; }
Best Regards