【发布时间】:2013-12-22 20:44:50
【问题描述】:
正在将文本内容显示到文本块中。正在从列表中检索数据。反复按下按钮会更改列表中文本块的内容。我的代码显示列表中的所有文本,并在显示所有文本时通知用户。
例如,如果我的列表中有100个项目,那么用户的操作将一一出现总共100个问题。我想要的是如何设置它来填充我的 100 个问题中的 10 个。因此,显示 10 条文本后将显示一条完整的消息。我还想在每个文本更改时随机化和打乱列表。所以用户每次打开页面都会遇到不同的事情(至少在一段时间内)。 这是我的代码:
public partial class _008Test : PhoneApplicationPage
{
private List<Question> questionList;
int currentQuestionIndex = 0;
private Question currentQuestion;
int Score = 0;
public _008Test()
{
InitializeComponent();
InitializeComponent();
questionList = new List<Question>();
questionList.Add(new Question { Text = "This is the first question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the second question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the third question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the forth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the fifth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the sixth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the seventh question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the eitht question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the ninth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the tenth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the first question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the second question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the third question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the forth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the fifth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the sixth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the seventh question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the eitht question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
questionList.Add(new Question { Text = "This is the ninth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 1 });
questionList.Add(new Question { Text = "This is the tenth question", Answers = new List<string> { "A", "B", "C", "D" }, CorrectAnswer = 2 });
loadquestion(currentQuestionIndex);
}
private void loadquestion(int questionindex)
{
currentQuestion = questionList[questionindex];
}
private void Next_Click(object sender, System.EventArgs e)
{
Score++;
currentQuestionIndex++;
if (currentQuestionIndex < questionList.Count)
{
loadquestion(currentQuestionIndex);
}
else
{
MessageBox.Show("You have finished!" + "Score is: " + Score);
}
}
}
上面的列表可以包含 20 个文本。我想让它达到 100 甚至更多。但我只能显示一切。我将如何只显示 10。所以必须重新打开页面才能启动另一个文本会话。
【问题讨论】:
-
它是一个 Windows 手机应用程序。一道银光。不使用 wpf。
标签: c# arrays windows-phone-8 visual-studio-2013 textblock