Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
Hello Everyone, I have classes in my application generated by Json :-

public class Answer
 { 
public string answerId { get; set; }
 public string answer { get; set; }
 }

C#
public class Question
{
    public string questionId { get; set; }
    public string questionTitle { get; set; }
    public string storyUrl { get; set; }
    public string correctAnswerId { get; set; }
    public List<Answer> answers { get; set; }
}

public class Main
{
    public string response { get; set; }
    public string message { get; set; }
    public string questionType { get; set; }
    public string device_id { get; set; }
    public string quiz_type { get; set; }
    public int totalQuestion { get; set; }
    public List<Question> questions { get; set; }
}

I use webclient for this &
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wcDownloadStringCompleted);
wc.DownloadStringAsync(new Uri("my url", UriKind.RelativeOrAbsolute));
now I have to bind data in my xaml. I bind the first question & its option from this code:- my method wcDownloadStringCompleted() consist:-

Main obj = JsonConvert.DeserializeObject(e.Result);

Question ques = new Question
{
questionTitle = obj.questions.Last().questionTitle,
answers = obj.questions.Last().answers.Select(ans => new Answer { answer = ans.answer, answerId = ans.answerId }).ToList(),
questionId = obj.questions.Last().questionId,
storyUrl = obj.questions.Last().storyUrl,
correctAnswerId = obj.questions.Last().correctAnswerId

};
txt.DataContext = ques.questionTitle; // text block
rb1.Content = ques.answers.ElementAt(0).answer; // radio buttons
rb2.Content = ques.answers.ElementAt(1).answer;
rb3.Content = ques.answers.ElementAt(2).answer;
rb4.Content = ques.answers.ElementAt(3).answer;

now my problem starts;- 1. how do i check if a user select any option and click on "Submit" button to get right answer. 2. a "Next" button to get next question
please help me...
Posted

Use observable collections of questions and bind to the ui.

after finishing all the questions user will hit submit button there you just read the observable collection it contains the answers selected by the user.
 
Share this answer
 
Comments
rishiraj malvi 13-Feb-14 6:14am    
can you please show how i would be done please...
i am a novice in windows phone
it get all the question & option on next button by declaring List<question> question and get all values from obj of main.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900