开发者

list box item issue when navigate by using back key

I have a list box and when clicked on the list item it goes to its detail page.and when i pressed the back key from detail page and after that if i again clicked the sale list item does not navigate to the detail page but if i clicked other items in the list it navigate to the corresponding detail page. Actually i am not reloading the list box on back key pressed .I just pop up it from the back stack.if I reload the list box the issue is not there.Is there any solution for this issue .below is my code.

ListViewPage

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (DetailPage.isBackkeyPressed && list != null)
    {
        DetailPage.isBackkeyPressed = false;
    }
    else
    {
        ListDetails(); //Reloading the page if list is empty
    }

    base.OnNavigatedTo(e);
}

private void listBox_SelectionChanged(object sender, SelectionChan开发者_StackOverflow中文版gedEventArgs e)
{
    if (listBox.SelectedIndex >= 0)
    {
        (Application.Current as App).obj_list = list[listBox.SelectedIndex];
        NavigationService.Navigate(new Uri("/DetailPage.xaml", UriKind.Relative)); //Navigate to detail page
    }
}

DetailPage

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
    isBackkeyPressed = true;//flag  for check if back key is pressed
    base.OnBackKeyPress(e);
}


You need to unset the SelectedIndex, by setting it to -1, like this:

private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (listBox.SelectedIndex >= 0)
    {
        (Application.Current as App).obj_list = list[listBox.SelectedIndex];
        NavigationService.Navigate(new Uri("/DetailPage.xaml", UriKind.Relative)); //Navigate to detail page

        listBox.SelectedIndex = -1;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜