PhotoVM.cs 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Diagnostics;
  3. using Windows.UI.Xaml;
  4. using Windows.UI.Xaml.Media;
  5. using Windows.UI.Xaml.Media.Imaging;
  6. namespace YJMPD_UWP.ViewModels
  7. {
  8. public class PhotoVM : TemplateVM
  9. {
  10. DispatcherTimer timer;
  11. int secondsleft = 60;
  12. public PhotoVM() : base("Photo")
  13. {
  14. timer = new DispatcherTimer();
  15. timer.Interval = TimeSpan.FromSeconds(1);
  16. timer.Tick += Timer_Tick;
  17. timer.Start();
  18. }
  19. private void Timer_Tick(object sender, object e)
  20. {
  21. NotifyPropertyChanged(nameof(TimeOut));
  22. secondsleft--;
  23. if(secondsleft <= 0)
  24. {
  25. timer.Stop();
  26. secondsleft = 60;
  27. App.Game.StopGame();
  28. }
  29. }
  30. public string TimeOut
  31. {
  32. get
  33. {
  34. return "Take a photo within " + secondsleft + " seconds";
  35. }
  36. }
  37. }
  38. }