c# - Windows Phone 8.1 通过按住选择 ListView 中的项目

标签 c# listview windows-phone-8.1

有没有办法在 Windows Phone 8.1 中使用 holding 事件选择 ListView 中的项目?

如果我使用一次点击,我使用这段代码并且它工作正常

private void LstMyListView_Tapped(object sender, TappedRoutedEventArgs e)
{
  MyItem myItem = LstMyListView.SelectedItem as MyItem;
}

myItem 包含我选择的项目的数据

但是,如果我使用这段代码

private void LstMyListView_Holding(object sender, HoldingRoutedEventArgs e)
{
  MyItem myItem = LstMyListView.SelectedItem as MyItem;
}

myItem 结果为空。

如何通过 hold 事件获取选中的项目?

谢谢!

最佳答案

您应该能够从 DataContext 中检索您的项目并执行转换,例如:

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
    }
}

关于c# - Windows Phone 8.1 通过按住选择 ListView 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26928431/

相关文章:

android - ScrollView 中的 ListView 在 Android 上不滚动

c# - 如何在 Windows Phone 8.1 应用程序中扫描二维码? (不是 silverlight 应用程序)?

Android:如何根据数组值动态显示/隐藏 ListView 项目中的元素?

c# - 将 WP 8.1 SilverLight 升级到 WP 8.1 Universal 时 ApplicationData.LocalSettings 会发生什么

c# - 在 GetStringAsync 中处理 http 响应代码

c# - IDictionary<string, string> 与 Dictionary<string, string>

c# - XmlDocument.LoadXml 和 XDocument.Parse 之间的不同行为

c# - 请在特定于平台的项目中调用 CachedImageRenderer.Init 方法以使用 FFImageLoading?

c# - 自定义组件上的 Blazor 双向绑定(bind)

Delphi: ListView 中不必要的列线和没有 RowSelect (SysListView32)