PageRenderTime 14ms CodeModel.GetById 6ms app.highlight 4ms RepoModel.GetById 2ms 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//===================================================================================
17using System.Collections.Generic;
18using System.Diagnostics;
19using System.Text;
20using System.Windows.Input;
21using Microsoft.Practices.Prism.Commands;
22
23namespace BasicMVVMApp
24{
25    public class QuestionnaireViewModel
26    {
27        private readonly Questionnaire questionnaire;
28
29        public QuestionnaireViewModel()
30        {
31            this.questionnaire = new Questionnaire();
32            this.AllColors = new[] { "Red", "Blue", "Green" };
33            this.SubmitCommand = new DelegateCommand<object>(this.OnSubmit);
34        }
35
36        public Questionnaire Questionnaire
37        {
38            get { return this.questionnaire; }
39        }
40
41        public IEnumerable<string> AllColors { get; private set; }
42
43        public ICommand SubmitCommand { get; private set; }
44
45        private void OnSubmit(object obj)
46        {
47            Debug.WriteLine(this.BuildResultString());
48        }
49
50        private string BuildResultString()
51        {
52            StringBuilder builder = new StringBuilder();
53            builder.Append("Name: ");
54            builder.Append(this.questionnaire.Name);
55            builder.Append("\nAge: ");
56            builder.Append(this.questionnaire.Age);
57            builder.Append("\nQuestion 1: ");
58            builder.Append(this.questionnaire.Quest);
59            builder.Append("\nQuestion 2: ");
60            builder.Append(this.questionnaire.FavoriteColor);
61            return builder.ToString();
62        }
63    }
64}