PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PageHistoryManager.cs 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. namespace CaritasPWA.Shared {
  6. public class PageHistoryManager {
  7. private List<string> previousPages;
  8. public PageHistoryManager() {
  9. previousPages = new List<string>();
  10. }
  11. public void Reset() {
  12. previousPages.Clear();
  13. }
  14. public void AddPageToHistory(string pageName) {
  15. previousPages.Add(pageName);
  16. }
  17. public string GetPreviousPage() {
  18. if (CanGoBack()) {
  19. // You add a page on initialization, so you need to return the 2nd from the last
  20. string previousPage = previousPages.ElementAt(previousPages.Count - 2);
  21. previousPages.RemoveAt(previousPages.Count - 1);
  22. previousPages.RemoveAt(previousPages.Count - 1);
  23. return previousPage;
  24. }
  25. // Can't go back because you didn't navigate enough
  26. return previousPages.FirstOrDefault();
  27. }
  28. public bool CanGoBack() {
  29. return previousPages.Count > 1;
  30. }
  31. }
  32. }