MainViewModel.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using GalaSoft.MvvmLight;
  2. using Editor.Model;
  3. namespace Editor.ViewModel
  4. {
  5. /// <summary>
  6. /// This class contains properties that the main View can data bind to.
  7. /// <para>
  8. /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
  9. /// </para>
  10. /// <para>
  11. /// See http://www.galasoft.ch/mvvm/getstarted
  12. /// </para>
  13. /// </summary>
  14. public class MainViewModel : ViewModelBase
  15. {
  16. private readonly IDataService dataService;
  17. /// <summary>
  18. /// The <see cref="WelcomeTitle" /> property's name.
  19. /// </summary>
  20. public const string WelcomeTitlePropertyName = "WelcomeTitle";
  21. private string welcomeTitle = string.Empty;
  22. /// <summary>
  23. /// Gets the WelcomeTitle property.
  24. /// Changes to that property's value raise the PropertyChanged event.
  25. /// </summary>
  26. public string WelcomeTitle
  27. {
  28. get
  29. {
  30. return welcomeTitle;
  31. }
  32. set
  33. {
  34. if (welcomeTitle == value)
  35. {
  36. return;
  37. }
  38. welcomeTitle = value;
  39. RaisePropertyChanged(WelcomeTitlePropertyName);
  40. }
  41. }
  42. /// <summary>
  43. /// Initializes a new instance of the MainViewModel class.
  44. /// </summary>
  45. public MainViewModel(IDataService dataService)
  46. {
  47. this.dataService = dataService;
  48. dataService.GetData((item, error) =>
  49. {
  50. if (error != null)
  51. {
  52. // Report error here
  53. return;
  54. }
  55. WelcomeTitle = item.Title;
  56. });
  57. }
  58. public override void Cleanup()
  59. {
  60. base.Cleanup();
  61. }
  62. }
  63. }