MatchVM.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Windows.UI.Xaml.Media;
  2. using Windows.UI.Xaml.Media.Imaging;
  3. namespace YJMPD_UWP.ViewModels
  4. {
  5. public class MatchVM : TemplateVM
  6. {
  7. public MatchVM() : base("Match")
  8. {
  9. Error = "";
  10. Message = "";
  11. App.Game.OnDestinationEnter += Game_OnDestinationEnter;
  12. App.Game.OnDestinationLeave += Game_OnDestinationLeave;
  13. }
  14. private void Game_OnDestinationLeave(object sender, System.EventArgs e)
  15. {
  16. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  17. {
  18. if (App.Game.Selected)
  19. Error = "Return to location!";
  20. NotifyPropertyChanged(nameof(ErrorVisible));
  21. NotifyPropertyChanged(nameof(Error));
  22. });
  23. }
  24. private void Game_OnDestinationEnter(object sender, System.EventArgs e)
  25. {
  26. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  27. {
  28. if (App.Game.Selected)
  29. Error = "";
  30. if (!App.Game.Selected)
  31. Message = "You reached the destination!";
  32. NotifyPropertyChanged(nameof(ErrorVisible));
  33. NotifyPropertyChanged(nameof(Error));
  34. NotifyPropertyChanged(nameof(MessageVisible));
  35. NotifyPropertyChanged(nameof(Message));
  36. });
  37. }
  38. public bool MessageVisible
  39. {
  40. get
  41. {
  42. return Message != "";
  43. }
  44. }
  45. public bool ErrorVisible
  46. {
  47. get
  48. {
  49. return Error != "";
  50. }
  51. }
  52. public string Message
  53. {
  54. get; private set;
  55. }
  56. public string Error
  57. {
  58. get; private set;
  59. }
  60. public ImageSource Photo
  61. {
  62. get
  63. {
  64. return new BitmapImage(new System.Uri(App.Photo.Photo));
  65. }
  66. }
  67. }
  68. }