The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
e.Cancel = true; in OnNavigatingFrom breaks navigation RRS feed

  • Question

  • In OnNavigatingFrom() I check to see if a popup is displayed and if it is I close the popup and cancel the back button with e.Cancel = true;

    The problem is that the back button and other navigation no longer work after the e.Cancel = true.

    If I click the windows menu button and then come back into the app the back button and other navigation begin working again.

    Any ideas?
    Saturday, January 15, 2011 2:15 AM

Answers

  • Hi,

    It might help if we can see a small section of the code that is related to this. Do you have an OnBackKeyPress override too? There might be something there causing this.
    Saturday, January 15, 2011 2:19 AM
  • In OnNavigatingFrom() I check to see if a popup is displayed and if it is I close the popup and cancel the back button with e.Cancel = true;



    Why in OnNavigatingForm()? Do it in OnBackKeyPress() event. It is sure to work. I do it regularly.
    Saturday, January 15, 2011 2:39 AM
  • Here you go I just got home and grabbed the code I use.
    You will need to set a string variable PopUpOpen = "true" when it is open and false when you close it.  note this is a string variable
            protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) 
            { 
     
                    if (PopUpOpen == "true"
                    { 
                        e.Cancel = true
                    } 
                    else 
                    { 
     
                    } 
                     
                } 

    Saturday, January 15, 2011 2:46 AM
  • Thanks guys. That is exaclty what was wrong. I guess I didn't know there was an OnBackKeyPress().
    Sunday, January 16, 2011 4:19 AM

All replies

  • Hi,

    It might help if we can see a small section of the code that is related to this. Do you have an OnBackKeyPress override too? There might be something there causing this.
    Saturday, January 15, 2011 2:19 AM
  • In OnNavigatingFrom() I check to see if a popup is displayed and if it is I close the popup and cancel the back button with e.Cancel = true;



    Why in OnNavigatingForm()? Do it in OnBackKeyPress() event. It is sure to work. I do it regularly.
    Saturday, January 15, 2011 2:39 AM
  • Here you go I just got home and grabbed the code I use.
    You will need to set a string variable PopUpOpen = "true" when it is open and false when you close it.  note this is a string variable
            protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) 
            { 
     
                    if (PopUpOpen == "true"
                    { 
                        e.Cancel = true
                    } 
                    else 
                    { 
     
                    } 
                     
                } 

    Saturday, January 15, 2011 2:46 AM
  • Thanks guys. That is exaclty what was wrong. I guess I didn't know there was an OnBackKeyPress().
    Sunday, January 16, 2011 4:19 AM
  • You will need to set a string variable PopUpOpen = "true" when it is open and false when you close it.  note this is a string variable


    @CyiDev,

    You don't have to have a separate varialbe. There is a get / set property, IsOpen, on a popup. When you set it true / false, the popup is shown / hidden respectively. When you read it, you will get to know whether it is open or not.
    Sunday, January 16, 2011 4:39 AM
  • You will need to set a string variable PopUpOpen = "true" when it is open and false when you close it.  note this is a string variable


    @CyiDev,

    You don't have to have a separate varialbe. There is a get / set property, IsOpen, on a popup. When you set it true / false, the popup is shown / hidden respectively. When you read it, you will get to know whether it is open or not.

    Good to know.  I use the code above I posted as part of my history for my web browser.  Which I do need to tweak a little bit tomorrow.  I have tweaked it in my app, just need to tweak it in the how-to.  I really wish there was an proper way to handle the web-browser history.  (back) etc.
    Sunday, January 16, 2011 5:54 AM