Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

PIN Confirmation Navigation Issue

emcueemcue Member ✭✭

Hello community!

I'm working on my first Xamarin Forms project and have been relatively closely following the Enterprise Application Patterns using Xamarin.Forms eBook but am currently confounded by a bit of functionality we need to provide.

A user can choose to "secure" the app with a PIN. The problem I'm having is working out how to effectively navigate between the PincodeView which contains a FormsPinView and a label and the other views that need to use it.

As an example, from the SettingsView a may turn off the use of a PIN. If they attempt this then I need to get the user to re-enter their PIN to ensure that it's not one of their pesky children. I had planned to simply navigate to the PincodeView, use the MessagingCenter to inform the SettingsView whether the PIN was entered correctly, navigate back to the SettingsView and then remove the PincodeView from the NavigationStack.

Unfortunately, as has been noted on this forum before you cannot remove the last page in the NavigationStack.

The use case above is but one example and the PincodeView may be used from any view in the app due to an idle timeout that is yet to be implemented.

I have done quite a bit of googling to no avail. A colleague suggested that I implement some form of popup view to enter the PIN. While that may work (and look a tad sexier than a full screen view) it seems a bit like avoiding the design problem rather than understanding it (not to mention the fact that my scratchpad project can no longer be deployed to an Android emulator once it was included).

Anyway, I'll stop rambling but would be very interested in any way that you may have solved this design problem in the past.


PS. My apologies for the lack of links. I had many references in here but as a noob I'm not permitted to provide links...


  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    What we do is remain on the same PINView for the initial entry of and confirmation of the PIN. Then there is no problem with the navigation stack.
  • emcueemcue Member ✭✭

    Thanks for your time JamesLavery, but I'm afraid I'm a little confused. When the user sets their pin I do use the same PINView for the double entry required without any issue with the stack.

    My issue comes at other times when PIN validation is required. For instance, before I allow the users to change their PIN I need to ensure that they know their existing PIN. To do this I am displaying the PINView. The problem arises because, after PIN validation, I am navigating back to the SettingsView. This leaves the PINView in the last position in the navigation stack which can't be removed.

    One option I think I may have is to know which ViewModel has requested the PINViewModel so that instead of returning to the previous view I can navigate to the correct view. Then the PINView would be second last on the stack and could be removed. This has a smell to it though.

    I can't help but think I've missed something fundamental here as I'm sure I'm not the first person to attempt this.

  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    How are you navigating *back*? This should be a navigation pop which removes the PIN page from the stack.

    Can you post your code? Don't forget to format it.
  • emcueemcue Member ✭✭

    Thanks James, your direct query of how I was going back put me on the right track. I was using a pop so the page was being removed successfully, however upon attempting to modify the PIN again another PINView was being placed on the NavigationStack. As you may have surmised by now, for each time I ran through this process I was gaining another PINView.

    My problem was with the messaging as I wasn't unsubscribing from the message appropriately but subscribing each time.

    I now have a functional and much neater PIN management routine.

    Thanks again for your time.

Sign In or Register to comment.