Skip to main content

Microsoft Silverlight

Unanswered Question Drag and drop onto custom gridRSS Feed

(0)

gnop
gnop

Member

Member

8 points

27 Posts

Drag and drop onto custom grid

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 Tang - MSFT
Min-Hong...

Contributor

Contributor

3375 points

377 Posts

Re: Drag and drop onto custom grid

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

Min-Hong Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities