none
OnNavigatedto Looping Error (cant go back)

    General discussion

  • Hi Everyone,

    Just starting to make an app, and having some issues with the OnNavigatedTo function....


    Whats supposed to happen is when i click on the button to launch the page, it should automatically redirect the page to a pdf file on the internet.

    When I press back, it should take me back to the main page.

    Whats happening is when I click back, it takes me briefly to the redirection page, then reloads the pdf file.

    I know I've done something silly here, please help and explain where I went wrong?

     public partial class Page2 : PhoneApplicationPage
        {
            public Page2()
            {
                InitializeComponent();
            }
    
            protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                base.OnNavigatedTo(e);
    
                WebBrowserTask task = new WebBrowserTask() { URL ="http://testpage.com/test/test.pdf"};
                task.Show();
    
            }
            protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
            {
                e.Cancel = true;
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
    
        }
    }
    Tuesday, February 28, 2012 2:55 AM

All replies

  • Hello,

    My advise would be to not use a Page just to redirect to a Web page. You should put the WebBrowserTask in the Tap/Click event of the parent page.

    If you really want to keep the page2 workflow, you must add a condition statement in the OnNavigatedTo in order to distinguish common navigation to the page and the back navigation:

    if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
    {
    	NavigationService.GoBack(); // Go back to the previous page MainPage.xaml
    }
    else
    {
    	base.OnNavigatedTo(e);
    	WebBrowserTask task = new WebBrowserTask() { URL ="http://testpage.com/test/test.pdf"};
    	task.Show();
    }

    Hope this helps

    Tuesday, March 27, 2012 9:03 AM