开发者

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 List开发者_C百科boxItem 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());
                }

            }
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜