0
votes

I'm writing a WP8 app. In the mainpage I've a longlistselector, if I tap an item and navigate to another page, when I press the back button from the second page and come back to the mainpage if I tap the same item again nothing happens, but if I tap a different item it works as it should. _Here it is the ode for the function of the listener of the lls

private void MessageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (MessageList.SelectedItem == null)
    {
        return;
    }

    Contact c = (Contact)MessageList.SelectedItem;

    long id = c.ID;

    NavigationService.Navigate(new Uri("/ChatPage.xaml?ID=" + id.ToString(), UriKind.Relative));

    MessageList.SelectedItem = null;
}

As you can see I've already resetted the selected item, but the lls behaves the same way

Hope you can help me, thanks in advice!

1
I think your problem is that you've set SelectedItem to null. coming back the list probably thinks you haven't clicked on something new and doesn't set SelectedItem to the clicked item. Try not setting it to null.Peter Ritchie
I added .SelectedItem = null; to try to solve this problem, but it didn't help me... It behaves the same way if I comment that linegiofx

1 Answers

0
votes

Try handling it in the OnNavigatedTo event

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    MessageList.SelectedItem = null;
}

Then your SelectionChanged gets changed to:

private void MessageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (MessageList.SelectedItem == null)
    {
        return;
    }
    Contact c = (Contact)MessageList.SelectedItem;
    long id = c.ID;
    NavigationService.Navigate(new Uri("/ChatPage.xaml?ID=" + id.ToString(), UriKind.Relative));
}