如何在Windows Phonw 8中执行Hold事件
本文关键字:执行 Hold 事件 Phonw Windows | 更新日期: 2023-09-27 18:29:41
我正试图处理我的WindowsPhone8项目上的挂起事件。
这是我列表的点击事件
private void lstData_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Bus selectedItemData = (sender as ListBox).SelectedItem as Bus;
if (selectedItemData != null)
{
var num = selectedItemData.Number;
var route = selectedItemData.Route;
NavigationService.Navigate(new Uri(string.Format("/Details.xaml?parameter1=" + num + "¶meter2=" + route), UriKind.Relative));
}
这是等待事件
private void lstData_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
MessageBoxResult m = MessageBox.Show("Would you like to add this bus to favorite list", "Add to Favorite", MessageBoxButton.OKCancel);
if(m==MessageBoxResult.OK)
{
Bus selectedItemData2 = (sender as ListBox).SelectedItem as Bus;
if (selectedItemData2 != null)
{
MessageBox.Show(selectedItemData2.Route);
}
}
}
问题是,当我调试时,Hold事件中的selectedItemData2为null。我不明白它怎么可能适用于tap事件而不适用于hold事件。请帮帮我!
一种可能的解释是点击和保持事件不是同时触发的。1) 尝试注释掉Tap事件,然后再次调试它。2) 如果发送方在保持事件的参数中包含ListBox,请尝试
当Hold事件触发时,您持有的项目未被选中。但是您可以访问保留事件中保留e.OriginalSource的项目。