Windows手机中的数据绑定 [英] Data binding in windows phone

查看:102
本文介绍了Windows手机中的数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone, I have classes in my application generated by Json :-

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




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; }
}



我使用webclient进行此操作

wc.DownloadStringCompleted + = new DownloadStringCompletedEventHandler(wcDownloadStringCompleted);

wc.DownloadStringAsync(new Uri(my url,UriKind.RelativeOrAbsolute));

现在我必须在我的xaml中绑定数据。我绑定了第一个问题&它的选项来自这段代码: - 我的方法wcDownloadStringCompleted()包括: -



主要obj = JsonConvert.DeserializeObject(e.Result);



问题疑问=新问题

{

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 < br $>


};

txt.DataContext = ques.questionTitle; //文本块

rb1.Content = ques.answers.ElementAt(0).answer; //单选按钮

rb2.Content = ques.answers.ElementAt(1).answer;

rb3.Content = ques.answers.ElementAt(2).answer;

rb4.Content = ques.answers.ElementAt(3).answer;



现在我的问题开始了; - 1.我怎么做检查用户是否选择了任何选项并单击提交按钮以获得正确答案。 2.下一个问题的下一步按钮

请帮助我...


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...

推荐答案

使用可观察的问题集合并绑定到ui。



完成所有问题后,用户将点击提交按钮,您只需阅读其中包含用户选择的答案的可观察集合。
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.


它得到了所有问题&通过声明List< question>而在下一个按钮上显示选项提问并从主要的obj获取所有值。
it get all the question & option on next button by declaring List<question> question and get all values from obj of main.


这篇关于Windows手机中的数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆