1
votes

I got a problam with my WP8.1 application. I have a listView and when I tap on item, it get me to a new page with détails but then when I go back to my listView, I can retap the same item but it don't get me anywhere.

Here is my listView SelectionChanged Handler in MainPage.xaml.cs.

private void lvNom_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        Person personneSelect = (Person)lvNom.SelectedItem;
        Frame.Navigate(typeof(DetailPersonne), personneSelect);      
    }

Here is the code behind the page I need to show in DetailPersonne.xaml.cs

    public sealed partial class DetailPersonne : Page
{
    public Person person;
    public DetailPersonne()
    {
        this.InitializeComponent();

    }
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        person = e.Parameter as Person;

        if(string.IsNullOrEmpty(person.Nom) == true){
            tbNom.Text = "Non renseigné.";
        }
        else{
             tbNom.Text = person.Nom;
        }
        if (string.IsNullOrEmpty(person.Prenom) == true)
        {
            tbPrenom.Text = "Non renseigné.";
        }
        else{
        tbPrenom.Text = person.Prenom;
        }

the only navigation change I've done is handling the hardware back button in my App.xaml.cs

  public App()
    {
        this.InitializeComponent();
        this.Suspending += this.OnSuspending;
        HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    }
    void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;
        if(rootFrame != null && rootFrame.CanGoBack)
        {
            e.Handled = true;
            rootFrame.GoBack();
        }
    }

So if anyone got a fix for that it'll be nice ! Thanks in advance ! :)

1

1 Answers

0
votes

try resetting the selected item as SelectionChanged is not firing because the Selection hasnt changed when you navigate back.

    private void lvNom_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if(lvNom.SelectedItem != null)
        {
            Person personneSelect = (Person)lvNom.SelectedItem;
            lvNom.SelectedItem = null;
            Frame.Navigate(typeof(DetailPersonne), personneSelect);
        }      
    }