Exemple #1
0
        private void AddQuestion(StackLayout stack, Services.Section s)
        {
            selectQuestionType.IsVisible   = true;
            selectQuestionType.ItemsSource = new List <string> {
                "Multiple", "Text"
            };
            selectQuestionType.SelectedIndexChanged += (sender, args) =>
            {
                Services.Question question;
                switch (selectQuestionType.SelectedIndex)
                {
                case 0:
                    question = new Services.Question(Services.QuestionType.Multiple);
                    break;

                default:
                    question = new Services.Question(Services.QuestionType.Text);
                    break;
                }

                s.addQuestion(question);
                stack.Children.Add(GetQuestionView(question, s));
                selectQuestionType.IsVisible = false;
            };

            if (!selectQuestionType.IsFocused && selectQuestionType.IsVisible)
            {
                selectQuestionType.IsVisible = false;
            }
            selectQuestionType.Focus();
        }
Exemple #2
0
        private Grid GetQuestionView(Services.Question q)
        {
            Grid grid = new Grid();

            Label instruction = new Label {
                Text = q.Instruction
            };

            grid.Children.Add(instruction, 0, 0);

            switch (q.Type)
            {
            case Services.QuestionType.Multiple:
                Picker options = new Picker();
                options.ItemsSource = q.Options;
                int index = q.Options.FindIndex(0, q.Options.Count, a => a == q.Answer);
                if (index > 0)
                {
                    options.SelectedIndex = index;
                }
                options.SelectedIndexChanged += (sender, args) => PickerIndexChanged(q, options.SelectedIndex);
                grid.Children.Add(options, 0, 1);
                break;

            case Services.QuestionType.Text:
                Entry inputText = new Entry();
                inputText.Text         = q.Answer;
                inputText.TextChanged += (sender, args) => EntryTextChanged(q, inputText.Text);
                grid.Children.Add(inputText, 0, 1);
                break;
            }

            return(grid);
        }
Exemple #3
0
        private StackLayout GetQuestionView(Services.Question q, Services.Section s)
        {
            StackLayout grid = new StackLayout();

            Button deleteQ = new Button {
                Text = "Delete Question"
            };

            deleteQ.Clicked += (sender, args) => {
                grid.IsVisible = false;
                s.removeQuestion(q);
            };
            grid.Children.Add(deleteQ);

            Entry changeQinstruction = new Entry {
                Text = q.Instruction
            };

            changeQinstruction.TextChanged += (sender, args) => { q.Instruction = changeQinstruction.Text; };
            grid.Children.Add(changeQinstruction);

            switch (q.Type)
            {
            case Services.QuestionType.Multiple:
                Label explainQ = new Label {
                    Text = "Insert the options seperated by a comma"
                };
                grid.Children.Add(explainQ);

                string optionsString = "";
                foreach (string item in q.Options)
                {
                    optionsString += $"{item},";
                }
                Entry changeQoptions = new Entry {
                    Text = optionsString
                };
                changeQoptions.TextChanged += (sender, args) => {
                    q.Options = new List <string>(changeQoptions.Text.Split(','));
                };
                grid.Children.Add(changeQoptions);
                break;

            default:
                break;
            }

            return(grid);
        }
Exemple #4
0
 private void EntryTextChanged(Services.Question q, string Text)
 {
     q.Answer = Text;
 }
Exemple #5
0
 private void PickerIndexChanged(Services.Question q, int newIndex)
 {
     q.Answer = q.Options[newIndex];
 }