MainViewModel.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Windows.Threading;
  3. using Editor.Model;
  4. using GalaSoft.MvvmLight;
  5. using GalaSoft.MvvmLight.Command;
  6. using GalaSoft.MvvmLight.Threading;
  7. namespace Editor.ViewModel
  8. {
  9. public class MainViewModel : ViewModelBase
  10. {
  11. private readonly IDataService dataService;
  12. private string loginResult = "";
  13. public MainViewModel(IDataService dataService)
  14. {
  15. this.dataService = dataService;
  16. LoginCmd = new RelayCommand(AsyncLogin);
  17. }
  18. public string LoginResult
  19. {
  20. get
  21. {
  22. return loginResult;
  23. }
  24. set
  25. {
  26. if (loginResult == value)
  27. {
  28. return;
  29. }
  30. loginResult = value;
  31. RaisePropertyChanged("LoginResult");
  32. }
  33. }
  34. public RelayCommand LoginCmd
  35. {
  36. get;
  37. private set;
  38. }
  39. private void AsyncLogin()
  40. {
  41. Action showLoginResult = () =>
  42. {
  43. LoginResult = "Login OK!";
  44. };
  45. AsyncCallback callback = (obj) =>
  46. {
  47. DispatcherHelper.UIDispatcher.BeginInvoke(
  48. DispatcherPriority.Normal, showLoginResult);
  49. };
  50. Action asynLogin = () =>
  51. {
  52. };
  53. asynLogin.BeginInvoke(callback, null);
  54. }
  55. public override void Cleanup()
  56. {
  57. base.Cleanup();
  58. }
  59. }
  60. }