MatchVM.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. App.Game.OnDestinationEnter += Game_OnDestinationEnter;
  10. App.Game.OnDestinationLeave += Game_OnDestinationLeave;
  11. }
  12. private void Game_OnDestinationLeave(object sender, System.EventArgs e)
  13. {
  14. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  15. {
  16. if (App.Game.Selected)
  17. Error = "Return to location!";
  18. NotifyPropertyChanged(nameof(ErrorVisible));
  19. NotifyPropertyChanged(nameof(Error));
  20. });
  21. }
  22. private void Game_OnDestinationEnter(object sender, System.EventArgs e)
  23. {
  24. dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
  25. {
  26. if (App.Game.Selected)
  27. Error = "";
  28. if (!App.Game.Selected)
  29. Message = "You reached the destination!";
  30. NotifyPropertyChanged(nameof(ErrorVisible));
  31. NotifyPropertyChanged(nameof(Error));
  32. NotifyPropertyChanged(nameof(MessageVisible));
  33. NotifyPropertyChanged(nameof(Message));
  34. });
  35. }
  36. public bool MessageVisible
  37. {
  38. get
  39. {
  40. return Message != "";
  41. }
  42. }
  43. public bool ErrorVisible
  44. {
  45. get
  46. {
  47. return Error != "";
  48. }
  49. }
  50. public string Message
  51. {
  52. get; private set;
  53. }
  54. public string Error
  55. {
  56. get; private set;
  57. }
  58. public ImageSource Photo
  59. {
  60. get
  61. {
  62. return new BitmapImage(new System.Uri(App.Photo.Photo));
  63. }
  64. }
  65. }
  66. }