从点获取ListView索引 - C#(Windows 8.1 Store App)

时间:2014-07-09 15:56:43

标签: c# listview drag-and-drop windows-8.1

我有一个简单的拖放功能在两个ListView元素之间工作,但我希望能够根据光标位置(而不是在开头或结尾)将对象拖放到ListView中。我已经设法从指针释放事件中将此点作为PointerPoint,但我无法弄清楚如何将其转换为ListView的正确索引。

不幸的是,.NET for Windows 8.1商店应用程序不存在ListView.GetItemAt(X,Y).Index(据我所知)。我可以使用它来获得索引吗?

我的代码如下所示:

public PointerPoint PP { get; set; }

// Called when pointer released over ListView
private void PointerRelease(object sender, PointerRoutedEventArgs e)
    {
        ListView lv = (ListView)sender;
        PP = e.GetCurrentPoint(lv);
    }

// Called when object dropped onto ListView
private void ListViewDrop(object sender, DragEventArgs e)
    {
            ListView dropListView = sender as ListView;
            int index = dropListView.GetItemAt(PP.Position.X, PP.Position.Y).Index;
            // Do drag/drop code
    }

0 个答案:

没有答案