How do I clear navigation history in Silverlight/Windows Phone 7?

前端 未结 5 1461
無奈伤痛
無奈伤痛 2021-02-10 08:18

I\'m making a Windows Phone 7 app that has login/logout semantics (authenticating to a web app). When the user logs out I navigate back to the login screen and forget the sessio

5条回答
  •  花落未央
    2021-02-10 09:23

    A simpler way to just clear the backstack is to do the following

    while (NavigationService.CanGoBack)
    {
        NavigationService.RemoveBackEntry();
    }
    

    Be aware though that if you do this in the onloaded event it will fire everytime the page is navigated to and clicking back again will close the app!

    Important note, that if you use a webcontrol or the NAX ad system, the backkey is consumed by the page as well as the web control, so will exist the app rather than return to a page.

    **Update Also just found an even shorter hand version from the MS dev center

    while (NavigationService.RemoveBackEntry() != null);
    

    One simple line. Nice

提交回复
热议问题