PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/Quickstarts/BasicMVVM/BasicMVVMApp/QuestionnaireViewModel.cs

#
C# | 64 lines | 41 code | 7 blank | 16 comment | 0 complexity | f3ec031b518e12fdacf952f9dec38ef8 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System.Collections.Generic;
  18. using System.Diagnostics;
  19. using System.Text;
  20. using System.Windows.Input;
  21. using Microsoft.Practices.Prism.Commands;
  22. namespace BasicMVVMApp
  23. {
  24. public class QuestionnaireViewModel
  25. {
  26. private readonly Questionnaire questionnaire;
  27. public QuestionnaireViewModel()
  28. {
  29. this.questionnaire = new Questionnaire();
  30. this.AllColors = new[] { "Red", "Blue", "Green" };
  31. this.SubmitCommand = new DelegateCommand<object>(this.OnSubmit);
  32. }
  33. public Questionnaire Questionnaire
  34. {
  35. get { return this.questionnaire; }
  36. }
  37. public IEnumerable<string> AllColors { get; private set; }
  38. public ICommand SubmitCommand { get; private set; }
  39. private void OnSubmit(object obj)
  40. {
  41. Debug.WriteLine(this.BuildResultString());
  42. }
  43. private string BuildResultString()
  44. {
  45. StringBuilder builder = new StringBuilder();
  46. builder.Append("Name: ");
  47. builder.Append(this.questionnaire.Name);
  48. builder.Append("\nAge: ");
  49. builder.Append(this.questionnaire.Age);
  50. builder.Append("\nQuestion 1: ");
  51. builder.Append(this.questionnaire.Quest);
  52. builder.Append("\nQuestion 2: ");
  53. builder.Append(this.questionnaire.FavoriteColor);
  54. return builder.ToString();
  55. }
  56. }
  57. }