Search code examples
windows-phone-7onresume

How to resume a page which is already opened in WP7?


How to resume a page which is already opened in WP7?

For example : In P1 there are two buttons A and B,when i click A it takes me to P2 and when i come back to P1 and again click A it not working. But after i click B which takes to P3 and come back to P1 and click A its working,but button B is not.

I understand that an instance of that page is already running in the background. But don't know how to resume that page while clicking the button again.

Can anyone help with what should be done here?


Solution

  • When you are navigating via SelectionChanged, you need to reset the SelectedIndex:

    public void SelectionChanged(object sender, SelectionChangedEventArgs e){
    
        var lb = (ListBox) sender;
    
        if (lb.SelectedIndex == -1) return;
    
        //do your logic here
        NavigationService.Navigate(///);
    
        //reset selected index
        lb.SelectedIndex = -1;
    
    }
    

    Edit: SelectedIndex is not available in LongListSelector. Use SelectedItem instead.

    void PersonSelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (buddies.SelectedItem == null) return;
                Person person = buddies.SelectedItem as Person;
                if (person != null)
                {
                    NavigationService.Navigate(new Uri("/Samples/PersonDetail.xaml?ID=" + person.ID, UriKind.Relative));
                }
    
                buddies.SelectedItem = null;
            }