如何从文本文件中读取字符串并将其拆分为4个单选按钮? (WPF)
问题描述:
我有一个包含问题和答案的猜谜的文本文件。如何从文本文件中读取字符串并将其拆分为4个单选按钮? (WPF)
m1 | mcq | Which of the following is an animal | table#cat#keyboard#water
m2 | mcq | which of the following is a programming language |C++#water#Air#Phone
m3 | mcq | which is the prime number | 3#4#8#10
我迄今为止的进展:
string[] lines = File.ReadAllLines(path);
string[] line = lines[0].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
string QuizQuestion = line[2].Trim();
string[] QuestionChoice = line[3].Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
textBox.Text = QuizQuestion;
foreach(?)
{
}
我试着用foreach循环,使我的单选按钮,像答案选择,但我不知道如何着手。我已插入标签和文本框我的单选按钮尝试哪一个成功了,但是我不
答
如果你总是有4个选择,你可以添加4个单选按钮到窗体中,把它们放在一个列表中,这样做的内这个:
string[] QuestionChoice = line[3].Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
List<RadioButton> radioButtonList = new List<RadioButton>();
radioButtonList.Add(radioButton1);
radioButtonList.Add(radioButton2);
radioButtonList.Add(radioButton3);
radioButtonList.Add(radioButton4);
for (int i = 0; i < radioButtonList.Count; i++)
{
radioButtonList[i].Content = QuestionChoice[i];
}
我忘了提这是WPF。单选按钮没有.Text。我也尝试做radiobutton.Test B4手 – NaviHam
呵呵谢谢了很多,测试的另一个会议结束后,我去查这个网站https://msdn.microsoft.com/en-us/library/system.windows.controls.radiobutton (v = vs.110).aspx,并发现单选按钮使用了“内容”。非常感谢 – NaviHam