Is it possible to detect if the user can go back? - durandal

Basically, I need to replicate the browser back button on my app (I do not want it, but I need to do it :/)
On durandal, I can navigate back by calling router.navigateBack();. But there is not always a page back (the browser back button get disabled when there is not). So, it is possible to detect if there is a previous page?
I am thinking in creating a simple counter that increments when the user navigate and decrement when it clicks on my "back" button, but I do not now how can I detect the user clicked the browser back button. If there is some way to know that there is not any previous page, it would be nice.

I was able to do this by intercepting the router.on('router:route:activating') event. When the user navigate, I increment a variable, when he goes back (router.navigatingBack will be true even if he clicked on the browser back button!) I decrement it. When it is 0, I disable the go back button.

Related

Close previous page after clicking Flyout in Xamarin.Forms

do you know how to set automatically close the previous page after clicking on Flyout Menu?
I don't want to keep this page in memory of my device, because it lags him.
Any ideas?
I try to create the method "button clicked" with this:
await Application.Current.MainPage.Navigation.PopAsync();
It didn't work.
The code you are trying removes the top Page from the navigation stack, in other words it only pops up one page at a time. You can use the INavigation.PushAsync method to add a page to the stack, which opens a new page on the screen, like this:
Application.Current.MainPage = new TestPage();
Usually you don't need to do anything to clear the previous page. The garbage collector will do this automatically for you (not immediately, but after some time depending on some circumstances).

What event is triggered whenever the app is dragged back into the current window?

I'm struggling with the activation lifecycle for my app. I just want to save the state for the current page whenever the app is hidden or whenever the user navigates to a different page. Conversely, I want to restore the state whenever the user launches my app or navigates back to that page.
In the following case, I detect that the app was made hidden so I store the page's state, but I never get notified that the app was reactivated so I can restore the state:
(on surface)
1. launch app
2. press start
3. drag app from left edge of screen and drop it back into focus
I was hoping the Resuming event would do it, but no. Which event should I use?
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.resuming.aspx
For the whole app, check Window.Activated, for individual pages you can use Page.OnNavigatedFrom / Page.OnNavigatedTo.

Is it possible to use the back button to move between PivotItems?

Part of my app switches PivotItems automatically when a user clicks on an item in a list. I want to allow the user to press the back button after this action to switch back to the original PivotItem. How could this be achieved? If my understanding is correct the normal BackStack can only be used with pages.
You can override the OnBackKeyPress() function and set e.Cancel to true to cancel the back key press (and navigate to a different PivotItem or whatever).
However: according to the certification requirements:
5.2.4.1 – Back button: previous pages
Pressing the Back button must return the app to the previous page or return to any previous page within the back stack.
So I wouldn't recommend doing something like this - not only is it likely to fail certification, it's also likely to confuse people.

OOB NewForm in Dialog loses focus after a few seconds

Working in SharePoint 2010, with SharePoint Designer 2010, I have a DispForm to which I've added a DVWP that displays a filtered view of another relative list. The DVWP has a 'New' link which opens the NewForm for that list in a modal dialog, using OpenPopUpPage (http://msdn.microsoft.com/en-us/library/ff410825.aspx).
After 5 - 12 seconds, the blinking cursor disappears from the first control and the focus switches to the 'Close' button. If the user was trying to type and happens to hit the Enter key when the focus switches to the 'Close' button, the background is no longer darkened and the 'Cancel' button no longer works. The form is still displayed on the screen, and the user can 'Save' but the modal never goes away until the page is refreshed.
If the user notices that the modal has lost focus and clicked back on the form, everything works as it should and all is well.
Observations:
When the control/modal loses focus, the 'Close' button does not trigger a 'focusin' event. But, $(document.activeElement).attr("value") displayed in the console shows that it's the active element.
Questions:
Why is the modal losing focus?
Does anyone have a Javascript/jQuery workaround to capture the event and set the focus back where it was?
Alternately, what if I lock the form and wait for this focus-change to complete, then unlock it and set the focus on the first field? Ideas?
You may be having a problem if the DispForm is also a dialog and you open the modal with your script. It sounds like you are getting a "layered" effect. My guess is that the script managing the dialog is interfering with the modal. Have you tried turning off the dialiogs for the list?
Just so I get some points on this site, the affliction was the asynchronous refresh of the first modal. It was taking the focus away from the layered modal.
Thanks JB for the answer!
I figured out the problem: the DVWP was using Auto-Refresh with the Async Update. This was running every 15 secs, taking the focus away from the modal, then not returning it to the last control.
So, we turned of the auto-refresh and used the callback from the modal close to trigger a click on the manual refresh button instead.

Can't retrieve the session on clicking of browser's back button

I have rails application that calculates prices of goods and I set prices in session. I have 'back' button in my application. When I clicks on 'back' link, I will get my previous session values like 'prices','goods' I purchased.
But when I clicks on 'browsers' back button,I won't get my session values, I have to refresh the page for that.
I'd say you have caching issues... The browser remembers what it saw before, and thinks it's the same (without even going to the trouble to ask the server any more). Try if this article helps
You probably want to prevent the browser from caching your pages so that they get refreshed when the user clicks the Back button. This article should help.