保持并获取ListView项目索引

时间:2015-05-25 18:08:41

标签: c# listview windows-phone runtime

我有一个ListView,其中包含以下内容:

1. One
2. Two
3. Three
4. Four
5. Five

当我持有其中一个时,我的hold事件被触发,我得到了项目的内容和索引,但是对于我来说,我必须在我持有它之前按下它。我需要在拿着物品时获得索引,而不必在之前按下它。

这是我的代码

private void ListViewItem_Holding(object sender, HoldingRoutedEventArgs e)
{  
    content = (sender as ListViewItem).Content.ToString();
    index = historico.SelectedIndex;
}

1 个答案:

答案 0 :(得分:2)

试试这个

private void ListViewItem_Holding(object sender, HoldingRoutedEventArgs e)
{  
    var item = (sender as FrameWorkElement).DataContext;
    //find index
    // index= yourItemSource.IndexOf(item );
}