MainViewModel.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Threading.Tasks;
  3. using System.Windows.Threading;
  4. using GalaSoft.MvvmLight;
  5. using GalaSoft.MvvmLight.Command;
  6. using GalaSoft.MvvmLight.Threading;
  7. namespace Egametang
  8. {
  9. public class MainViewModel : ViewModelBase
  10. {
  11. private Main main = new Main();
  12. private RelayCommand loginCmd = null;
  13. public MainViewModel()
  14. {
  15. loginCmd = new RelayCommand(AsyncLogin);
  16. }
  17. public string LoginResult
  18. {
  19. get
  20. {
  21. return main.LoginResult;
  22. }
  23. set
  24. {
  25. if (main.LoginResult == value)
  26. {
  27. return;
  28. }
  29. main.LoginResult = value;
  30. RaisePropertyChanged("LoginResult");
  31. }
  32. }
  33. public RelayCommand LoginCmd
  34. {
  35. get
  36. {
  37. return loginCmd;
  38. }
  39. }
  40. private void AsyncLogin()
  41. {
  42. var task = new Task(() =>
  43. {
  44. });
  45. task.ContinueWith(_ =>
  46. {
  47. DispatcherHelper.UIDispatcher.BeginInvoke(DispatcherPriority.Normal,
  48. new Action(() =>
  49. {
  50. LoginResult = "Login OK!";
  51. }));
  52. });
  53. task.Start(App.OrderedTaskScheduler);
  54. }
  55. public override void Cleanup()
  56. {
  57. base.Cleanup();
  58. }
  59. }
  60. }