locked
NavigationHelper.vb doesn't behave as expected RRS feed

  • Question

  • Hi,

    I've been looking for a solution to the problem that my Windows Phone 8.1 app doesn't navigate to the previous page, but goes to the previous app (and suspends my app). Everywhere I found that when using the NavigationHelper, the HardwareButton.BackPressed event should navigate within the app (so between pages) and not between apps, but whatever I try I can't get it to work.

    This is what I've done to test the behaviour in Visual Studio Express 2013:

    1. Create a new project
    2. Select the Blank App (Windows Phone) template under Visual Basic, Store Apps, Windows Phone Apps
    3. Remove MainPage.xaml from the Solution Explorer
    4. Add a new Basic page and call it MainPage.xaml
    5. Select Yes to add NavigationHelper.vb
    6. Add another new Basic page called Page2.xaml
    7. Create a button on MainPage to navigate to Page2 (Frame.Navigate(GetType(Page2)))

    When I run the app, I can navigate to Page2, but when I press the phones back button, the app is closed.

    When I do exactly the same but for C#, it works as I expect, pressing the back button on the phone takes me back to the main page in my app.

    When examining the code from NavigationHelper.vb and NavigationHelper.cs I noticed that in the vb version the specific code for windows phone (after #IF WINDOWS_PHONE_APP THEN) is greyed out, where in the cs file, the phone code is normal and everything not for phone is greyed out (after #ELSE in the same IF statement).

    Is this normal? What can I do to make the back button on the phone to go to the previous page in my app? Even when I run the code on my phone, it still suspends my app and goes to the previous one when I press the phones back button.




    • Edited by FlatBread Monday, September 8, 2014 1:04 PM
    Monday, September 8, 2014 12:57 PM

Answers

  • What I've done is remove the #IF WINDOWS_PHONE_APP... #ELSE statements and leave only the code for Windows Phone, as it's not a universal app anyway (and maybe universal apps are not yet supported in VB).

    That made it work again.

    • Proposed as answer by Terrence-Jones Tuesday, September 9, 2014 6:27 AM
    • Marked as answer by Yang,Chenfei Tuesday, September 23, 2014 2:55 AM
    Monday, September 8, 2014 1:23 PM

All replies

  • What I've done is remove the #IF WINDOWS_PHONE_APP... #ELSE statements and leave only the code for Windows Phone, as it's not a universal app anyway (and maybe universal apps are not yet supported in VB).

    That made it work again.

    • Proposed as answer by Terrence-Jones Tuesday, September 9, 2014 6:27 AM
    • Marked as answer by Yang,Chenfei Tuesday, September 23, 2014 2:55 AM
    Monday, September 8, 2014 1:23 PM
  • Thank you for sharing.
    Tuesday, September 9, 2014 6:27 AM