is there a way to select an item in a listview with the holding event in Windows Phone 8.1?
If I use a single tap, I use this code and it works fine
private void LstMyListView_Tapped(object sender, TappedRoutedEventArgs e)
{
MyItem myItem = LstMyListView.SelectedItem as MyItem;
}
myItem contains the data of my selected item
However, if I use this code
private void LstMyListView_Holding(object sender, HoldingRoutedEventArgs e)
{
MyItem myItem = LstMyListView.SelectedItem as MyItem;
}
myItem results as null.
How do I get the selected item with hold event??
Thank you!
You should be able to retrive your item from DataContext and perform a cast, for example like this:
private void LstMyListView_Holding(object sender, HoldingRoutedEventArgs e)
{
FrameworkElement element = (FrameworkElement)e.OriginalSource;
if (element.DataContext != null && element.DataContext is MyItem)
{
MyItem selectedOne = (MyItem)element.DataContext;
// rest of the code
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With