/Templates/ProjectTemplates/WPF/MvvmLight.WPF/MainViewModel.cs

#
C# | 75 lines | 40 code | 10 blank | 25 comment | 4 complexity | 6d577a6a42c68359423f6c18a6430017 MD5 | raw file

✨ Summary
  1. using GalaSoft.MvvmLight;
  2. using $safeprojectname$.Model;
  3. namespace $safeprojectname$.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. _dataService = dataService;
  48. _dataService.GetData(
  49. (item, error) =>
  50. {
  51. if (error != null)
  52. {
  53. // Report error here
  54. return;
  55. }
  56. WelcomeTitle = item.Title;
  57. });
  58. }
  59. ////public override void Cleanup()
  60. ////{
  61. //// // Clean up if needed
  62. //// base.Cleanup();
  63. ////}
  64. }
  65. }