How to perform Hold event in Windows Phonw 8?

早过忘川 提交于 2019-12-13 07:00:35

问题


I'm trying to deal with hold event on my Windows Phone 8 project.

This is my list's tap event

    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 + "&parameter2=" + route), UriKind.Relative));
        }

And this is Hold event

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

The problem is that selectedItemData2 in Hold event comes null when I debugged. I can't understand how it is possible that it work for tap event but not for hold event. Please help me!


回答1:


One possible explanation is that tap and hold events are not triggered simultaneously. 1) Try commenting out Tap event and debug it again. 2) Try if the sender contains the ListBox in the parameter of hold event




回答2:


When Hold event fired , the item you holded was not selected.But you can access the item which holded e.OriginalSource in your hold event.



来源:https://stackoverflow.com/questions/18548869/how-to-perform-hold-event-in-windows-phonw-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!