简体   繁体   English

在列表中拖放,Windows 8应用程序?

[英]Drag and drop within list, windows 8 app?

Is there any good examples/tutorials on how to implement drag and drop within a window 8 C# list (listview, listbox …) out there? 关于如何在窗口8 C#列表(listview,listbox…)中实现拖放,是否有任何好的示例/教程?

What I would like Is a editable “Iphone-list”-experience, where I easily can rearrange items within a list. 我想要的是一种可编辑的“ iPhone列表”体验,我可以轻松地重新排列列表中的项目。 But I mostly find WinJS examples and I would like to have ac# example for win 8 但是我主要是找到WinJS示例,我想为win 8提供一个ac#示例

Firstly You must enable the AllowDragDrop property. 首先,您必须启用AllowDragDrop属性。

Then write 3 events: 然后编写3个事件:

    private void myList_ItemDrag(object sender, ItemDragEventArgs e)
    {
        DoDragDrop(e.Item, DragDropEffects.Link);
    }

    private void myList_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Link;
    }

    private void myList_DragDrop(object sender, DragEventArgs e)
    {
        // do whatever you need to reorder the list.
    }

To get index of dropped item: 获取已删除项目的索引:

Point cp = myList.PointToClient(new Point(e.X, e.Y));
ListViewItem dragToItem = myList.GetItemAt(cp.X, cp.Y);
int dropIndex = dragToItem.Index;

If you need to drop onto a ListView or GridView, have the Drop event fire on the DataTemplate for the actual Item, not the whole list. 如果需要拖放到ListView或GridView上,请在DataTemplate上触发实际Item而不是整个列表的Drop事件。 Then you can tell which item it is dropped on. 然后,您可以知道放置在哪个项目上。

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

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