简体   繁体   中英

Silverlight: Determine which control initiated drag'n'drop

Using the drag'n'drop features of the Silverlight 4 Toolkit, I have a drag'n'drop enabled Listbox where each ListboxItem can be dragged/reordered up and down.

Each ListboxItem contains several controls (TextBlocks, TextBoxes and Buttons) and my problem is that when I click the buttons within a ListboxItem, I will occasionally initiate a drag event instead of just a click event on that control.

One solution would be to handle the ItemDragStarting event and determine what was clicked on to start the event - and cancel the event if called by a Button.

I can however not figure out how to determine what I've clicked on. Sender of the event and e.DragSource is of type ListBoxDragDropTarget, whether I initiate the drag from a button or the ListboxItem itself.

Any help would be appreciated - solutions to my problem or alternative methods of doing what I need!

You can drill down to the object type by using the following method:

private void OldFaithful_ItemDragStarting(object sender, ItemDragEventArgs e)
        {
            SelectionCollection selections = e.Data as SelectionCollection;

            if (selections != null)
            {
                IEnumerable<CXSectionControl> draggedItems = selections.Select(s => s.Item as YOUREXCPECTEDOBJECTTYPE);
                foreach (YOUREXCPECTEDOBJECTTYPE x in draggedItems)
                {
                    MessageBox.Show(x.GetType().ToString());
                }

            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM