public QuestionPage(Question question, Inspection inspection, string textOverride = null, List <Reference> extraReferences = null) { this.question = question; this.inspection = inspection; StackLayout layout = new StackLayout { Padding = new Thickness(20, 0), Spacing = 0, VerticalOptions = LayoutOptions.Center, }; Label SectionLabel = new Label { Text = "Section " + question.section.Label + ": " + question.section.Title, HorizontalOptions = LayoutOptions.Center, }; layout.Children.Add(SectionLabel); if (question.SectionPartId != null) { Label PartLabel = new Label { Text = "Part " + question.part.Label + ": " + question.part.Description, HorizontalOptions = LayoutOptions.Center, }; layout.Children.Add(PartLabel); } //Question number Label questionNumberlabel = new Label { Text = "Question " + question.numberString, HorizontalOptions = LayoutOptions.Center }; layout.Children.Add(questionNumberlabel); //Question text Label questionTextLabel = new Label(); if (textOverride == null) { questionTextLabel.Text = question.Text.Trim(); } else { questionTextLabel.Text = textOverride; } layout.Children.Add(questionTextLabel); //Answer score = inspection.GetScoreForQuestion(question); if (score != null) { HasScore = true; existingAnswerLabel.Text = "Answer: " + score.answer.ToString(); } else { HasScore = false; existingAnswerLabel.Text = ""; } layout.Children.Add(existingAnswerLabel); //Add Edit Comment Button Button commentButton = new Button(); commentButton.Text = "Add/Edit Comment For Question"; commentButton.Clicked += openCommentPage; layout.Children.Add(commentButton); //References buttons List <Reference> references = question.References; if (extraReferences != null) { //Creates a copy of the list so we aren't adding to the original. references = references.ToList(); references.AddRange(extraReferences); } foreach (Reference reference in references) { ReferenceButton referenceButton = new ReferenceButton(reference); referenceButton.folderName = inspection.ChecklistId; layout.Children.Add(referenceButton); } //Answer buttons List <AnswerButton> answerButtons = new List <AnswerButton>(); foreach (Answer answer in Enum.GetValues(typeof(Answer))) { AnswerButton button = new AnswerButton(answer); button.Text = answer.ToString(); button.Clicked += AnswerQuestion; layout.Children.Add(button); } //Clear scores button Button clearScoresButton = new Button { Text = "Clear Scores" }; clearScoresButton.Clicked += clearScores; layout.Children.Add(clearScoresButton); //Remarks label Label remarksLabel = new Label(); remarksLabel.Text = "Remarks:"; layout.Children.Add(remarksLabel); //Remarks box remarksBox = new Editor(); remarksBox.Text = question.Remarks; remarksBox.HeightRequest = 50; question.OldRemarks = question.Remarks; remarksBox.TextChanged += SaveRemarksText; layout.Children.Add(remarksBox); ScrollView scroll = new ScrollView(); scroll.Content = layout; Content = scroll; }
private void Setup() { SizeChanged += OnSizeChanged; StackLayout layout = new StackLayout { Padding = new Thickness(20, 28), Spacing = 0 //VerticalOptions = LayoutOptions.Center, }; layout.Children.Add( new StackLayout { Orientation = StackOrientation.Horizontal, Children = { // Section new Label { Text = "Section " + question.section.Label + ": " + question.section.Title, FontAttributes = FontAttributes.Bold, HorizontalOptions = LayoutOptions.StartAndExpand }, // Question Number new Label { Text = "Question " + question.numberString, HorizontalOptions = LayoutOptions.EndAndExpand, XAlign = TextAlignment.End, FontAttributes = FontAttributes.Bold } } } ); // Part if (question.SectionPartId != null) { layout.Children.Add( new StackLayout { Orientation = StackOrientation.Horizontal, Children = { new Label { Text = "Part " + question.part.Label + ": " + question.part.Description } } }); } layout.Children.Add(LayoutHelper.GetVerticalSpacing(20)); layout.Children.Add(LayoutHelper.GetHorizontalLine()); // Question text layout.Children.Add( new StackLayout { BackgroundColor = Color.FromHex("#ffd758"), Padding = new Thickness(10, 20, 10, 20), Children = { new Label { Text = (textOverride == null) ? question.Text.Trim() : textOverride, FontAttributes = FontAttributes.Italic } } }); layout.Children.Add(LayoutHelper.GetHorizontalLine()); //Add Edit Comment Button Button commentButton = new Button(); commentButton.Text = "Add/Edit Comment For Question"; commentButton.FontAttributes = FontAttributes.Italic; commentButton.Clicked += openCommentPage; commentButton.HorizontalOptions = LayoutOptions.End; layout.Children.Add(commentButton); layout.Children.Add(LayoutHelper.GetVerticalSpacing(5)); //Answer score = inspection.GetScoreForQuestion(question); if (score != null) { HasScore = true; var answer = EnumDescriptionAttribute.GetDescriptionFromEnumValue(score.answer); } else { HasScore = false; } // Answers - Radio Group var answers = Enum.GetValues(typeof(Answer)).Cast <Answer>().ToList(); var answerRadioGroup = new BindableRadioGroup { ItemsSource = answers.Select(x => EnumDescriptionAttribute.GetDescriptionFromEnumValue(x)), SelectedIndex = HasScore == true?answers.FindIndex(x => x.Equals(score.answer)) : -1 }; answerRadioGroup.Spacing = 12; answerRadioGroup.CheckedChanged += answerRadioGroup_CheckedChanged; answerRadioGroup.ItemUnchecked += answerRadioGroup_Unchecked; layout.Children.Add(new StackLayout { Children = { answerRadioGroup } }); layout.Children.Add(LayoutHelper.GetVerticalSpacing(25)); // References label layout.Children.Add(new Label { Text = "References:", FontAttributes = FontAttributes.Bold }); layout.Children.Add(LayoutHelper.GetVerticalSpacing(5)); layout.Children.Add(LayoutHelper.GetHorizontalLine()); //References buttons List <Reference> references = question.References; if (extraReferences != null) { //Creates a copy of the list so we aren't adding to the original. references = references.ToList(); references.AddRange(extraReferences); } foreach (Reference reference in references) { var referenceButton = new ReferenceButton(reference) { folderName = inspection.ChecklistId, FontAttributes = FontAttributes.Italic, HorizontalOptions = LayoutOptions.StartAndExpand }; layout.Children.Add( new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness(24, 0), HeightRequest = 30, Children = { new Label { TextColor = Color.FromHex("#2b90ff"), FontSize = 40, XAlign = TextAlignment.Center, Text = "\u2022" }, LayoutHelper.GetHorizontalSpacing(8), referenceButton } }); } layout.Children.Add(LayoutHelper.GetVerticalSpacing(25)); //Remarks label layout.Children.Add(new Label { Text = "Remarks:", FontAttributes = FontAttributes.Bold }); //Remarks box remarksBox = new Editor(); remark = inspection.GetRemarkForQuestion(question); if (App.IsPortrait(this)) { remarksBox.HeightRequest = 300; } else { remarksBox.HeightRequest = 100; } if (remark == null) { remarksBox.Text = string.Empty; question.OldRemarks = string.Empty; } else { remarksBox.Text = remark.remark; question.OldRemarks = remark.remark; } remarksBox.TextChanged += SaveRemarksText; layout.Children.Add(remarksBox); ScrollView scroll = new ScrollView(); scroll.Content = layout; Device.BeginInvokeOnMainThread(() => { Content = scroll; }); }