|
using System;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;
using System.Xml.Linq;
namespace EcoQuiz.ViewModel
{
public class QuizWizardViewModel : ViewModelBase
{
private int _questionIndex = 0;
private ResultsViewModel _results;
public QuizWizardViewModel(XDocument xml)
{
Title = xml.Root.Attribute("title").Value;
Questions = xml.Descendants("question")
.Select((questionElement, index) => new QuestionViewModel(index, questionElement, this))
.ToList();
}
public List<QuestionViewModel> Questions { get; set; }
public string Title { get; set; }
public ResultsViewModel Results
{
get { return _results; }
set
{
_results = value;
OnPropertyChanged("Results");
}
}
public QuestionViewModel CurrentQuestion
{
get
{
return _questionIndex >= Questions.Count ? null : Questions[_questionIndex];
}
}
public ICommand NextQuestionCommand
{
get
{
return new NextQuestionCommand(this);
}
}
public void NextQuestion()
{
_questionIndex++;
if (_questionIndex >= Questions.Count)
{
int correctQuestions = Questions.Count(q => q.SelectedAnswer.IsCorrect);
Results = new ResultsViewModel(correctQuestions, Questions.Count);
}
OnPropertyChanged("CurrentQuestion");
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.