Ameen
Ameen

Reputation: 1907

Tap Event Handler

It seems there is no Tap Event handler for the listbox in windows phone 7.0 as there is in 7.1
I found the SelectionChanged event however this event causes problem. So is there different event than Tap in 7.0??

private void flightlist_SelectionChanged(object sender, SelectionChangedEventArgs e)  
{    
PhoneApplicationService.Current.State["Flight"] = flightlist.SelectedItem;    
NavigationService.Navigate(new Uri("/FlightDetail", UriKind.Relative));    
}

Upvotes: 1

Views: 2600

Answers (2)

Claus Jørgensen
Claus Jørgensen

Reputation: 26347

The Silverlight Toolkit have a GestureListener that allows you to handle Tap, DoubleTap, and many more events.

It can be attached any element. But regardless, using a custom tap handler, for what the SelectionChanged event is for, is a stupid idea. You should clarify why it "causes problems" for you.

Update

Modify your code to this:

private void flightlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
{    
    if (flightlist.SelectedItem != null)
    {
        PhoneApplicationService.Current.State["Flight"] = flightlist.SelectedItem;
        NavigationService.Navigate(new Uri("/FlightDetail", UriKind.Relative));
    }

    // reset the selected-index, so the user can click on it again, after returning.
    flightlist.SelectedIndex = -1;
}

Upvotes: 5

Abbas
Abbas

Reputation: 14432

You can use the MouseLeftButtonUp-event of the ListBox and then get the selected item if there is one. Sample code:

private void YourListBox_LeftMouseButtonUp(object sender, MouseButtonEventArgs e)
{
    var listBox = sender as ListBox;
    var item = listBox.SelectedItem;
    if (item != null)
    {
        //do something with the item
    }
}

Upvotes: -1

Related Questions