private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e) { //TODO: Create an appropriate data model for your problem domain to replace the sample data while (Frame.BackStackDepth > 1) { Frame.BackStack.RemoveAt(Frame.BackStackDepth - 1); } Test newTest = await QuestionsDataSource.GetTestAsync(testname); for (int i = 0; i < newTest.questions.Count; i++) { TestQuestion question = newTest.questions[i]; StackPanel outerpanel = new StackPanel(); outerpanel.Orientation = Orientation.Vertical; TextBlock quesview = new TextBlock(); quesview.Text = question.question; outerpanel.Children.Add(quesview); if (question.type == "mcq") { RadioButton[] radioButtons = new RadioButton[question.choices.Count]; int j = 0; foreach (var kvp in question.choices) { radioButtons[j] = new RadioButton(); radioButtons[j].Content = kvp.Value; outerpanel.Children.Add(radioButtons[j++]); } } else if (question.type == "sub") { TextBox answer = new TextBox(); answer.HorizontalAlignment = HorizontalAlignment.Stretch; answer.VerticalAlignment = VerticalAlignment.Stretch; answer.TextWrapping = TextWrapping.Wrap; outerpanel.Children.Add(answer); } Hub.Children.Add(outerpanel); } }
private async Task GetQuestionsAsync(String testname) { string jsonText = ""; try { Windows.Storage.StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation; Uri dataUri = new Uri("ms-appx:///Assets/Tests/" + testname + ".json"); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); //StorageFile file = await StorageFile.GetFileFromPathAsync(installedLocation.Path + @"networktest.json"); jsonText = await FileIO.ReadTextAsync(file); } catch (Exception e) { var dialog = new MessageDialog("ms-appx:///Assets/Tests/" + testname + ".json"); await dialog.ShowAsync(); } JsonObject jsonObject = JsonObject.Parse(jsonText); _test = new Test(jsonObject["test"].GetString(), int.Parse(jsonObject["numques"].GetString()), new List <TestQuestion>()); JsonArray jsonArray = jsonObject["questions"].GetArray(); int qno = 0; foreach (JsonValue item in jsonArray) { qno++; JsonObject questionItem = item.GetObject(); TestQuestion question = new TestQuestion(qno, questionItem["question"].GetString(), questionItem["type"].GetString(), new Dictionary <string, string>()); JsonObject choices = questionItem["choices"].GetObject(); foreach (var choicename in choices.Keys) { question.choices.Add(choicename, choices[choicename].GetString()); } _test.questions.Add(question); } }
private async Task GetQuestionsAsync(String testname) { string jsonText=""; try { Windows.Storage.StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation; Uri dataUri = new Uri("ms-appx:///Assets/Tests/"+testname+".json"); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); //StorageFile file = await StorageFile.GetFileFromPathAsync(installedLocation.Path + @"networktest.json"); jsonText = await FileIO.ReadTextAsync(file); } catch(Exception e) { var dialog = new MessageDialog("ms-appx:///Assets/Tests/" + testname + ".json"); await dialog.ShowAsync(); } JsonObject jsonObject = JsonObject.Parse(jsonText); _test = new Test(jsonObject["test"].GetString(), int.Parse(jsonObject["numques"].GetString()), new List<TestQuestion>()); JsonArray jsonArray = jsonObject["questions"].GetArray(); int qno = 0; foreach (JsonValue item in jsonArray) { qno++; JsonObject questionItem = item.GetObject(); TestQuestion question = new TestQuestion(qno,questionItem["question"].GetString(), questionItem["type"].GetString(), new Dictionary<string, string>()); JsonObject choices = questionItem["choices"].GetObject(); foreach (var choicename in choices.Keys) { question.choices.Add(choicename,choices[choicename].GetString()); } _test.questions.Add(question); } }