我正在尝试处理我的 Windows Phone 8 项目中的保持事件。
这是我列表的点击事件
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));
}
这是Hold事件
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 为空。我无法理解它如何可能适用于点击事件而不适用于保持事件。请帮我!