简体   繁体   English

Silverlight:确定哪个控件启动了拖放

[英]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. 使用Silverlight 4 Toolkit的拖放功能,我启用了拖放功能的列表框,其中每个ListboxItem都可以上下拖动/重新排序。

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. 每个ListboxItem都包含几个控件(TextBlocks,TextBoxes和Buttons),我的问题是,当我单击ListboxItem中的按钮时,我偶尔会启动拖动事件,而不仅仅是在该控件上单击事件。

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. 一种解决方案是处理ItemDragStarting事件并确定单击了什么来启动该事件-如果被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. 事件的发件人和e.DragSource的类型为ListBoxDragDropTarget,无论我是启动按钮的拖动还是ListboxItem本身。

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());
                }

            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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