Beispiel #1
0
        protected override void Reevaluate()
        {
            if (_reevaluate != null)
            {
                _reevaluate(this);
            }

            if (!CurrentChoices.Contains(CurrentValue))
            {
                CurrentValue = CurrentChoices.FirstOrDefault();
            }
        }
Beispiel #2
0
        public ChoiceOption(string name, string display, IEnumerable <ValueType> choices, ValueType value, Action <ChoiceOption <ValueType> > reevaluate)
            : base(name, display, value)
        {
            CurrentChoices = choices.ToList();

            if (!CurrentChoices.Contains(CurrentValue))
            {
                CurrentValue = CurrentChoices.FirstOrDefault();
            }

            _reevaluate = reevaluate;
        }
        private void SwitchQuestion()
        {
            if (CurrentIndex < EachTimeQuestionsCount)
            {
                ChoicesVisibility = Visibility.Visible;
                ExplainVisibility = Visibility.Collapsed;
                CurrentQuestion   = CurrentQuestionGroup[CurrentIndex];
                CurrentIndex++;
                if (CurrentQuestion.Type == QuestionModel.QuestionType.TitleWithImage)
                {
                    CurrentChoicesLayout2.Clear();
                    FirstLayoutVisibility = Visibility.Collapsed;//Change FirstLayoutVisibility will change SecondLayoutVisibility automatically
                    for (int i = 0; i < CurrentQuestion.ChoiceCount; i++)
                    {
                        var ktb = new KinectTileButton();
                        ktb.Tag = i;

                        ktb.HorizontalAlignment      = HorizontalAlignment.Center;
                        ktb.VerticalAlignment        = VerticalAlignment.Center;
                        ktb.HorizontalLabelAlignment = HorizontalAlignment.Center;
                        ktb.VerticalLabelAlignment   = VerticalAlignment.Center;
                        ktb.LabelBackground          = new SolidColorBrush(Colors.Transparent);

                        ktb.Click += ktb_Click;
                        ktb.Height = DownContentHeight;
                        ktb.Width  = DownButtonWidth;

                        ktb.BorderThickness = new Thickness(0, 0, 0, 0);

                        ktb.Label = CurrentQuestion.Answers[i].Text;
                        ImageSource frameSource = new BitmapImage(new Uri("pack://application:,,,/Content/QuestionScreen/frame2.png"));
                        Image       frame       = new Image();

                        frame.Source  = frameSource;
                        frame.Stretch = Stretch.Fill;
                        ktb.Content   = frame;

                        double margin = ((RightScrollLen * 2 - CurrentQuestion.ChoiceCount * DownButtonWidth) /
                                         CurrentQuestion.ChoiceCount) / 2;
                        margin     = margin - margin / 4;
                        ktb.Margin = new Thickness(0, margin, 0, margin);

                        ImageBrush backBrush = new ImageBrush(new BitmapImage(new Uri(
                                                                                  "pack://application:,,,/Content/QuestionScreen/answerbg" + (i + 1) + ".png")));
                        backBrush.Opacity = 0.4;
                        backBrush.Stretch = Stretch.Fill;
                        ktb.Background    = backBrush;

                        CurrentChoicesLayout2.Add(ktb);
                    }
                    if (CurrentIndex == EachTimeQuestionsCount)
                    {
                        NextButtonImage = new BitmapImage(new Uri("pack://application:,,,/Content/QuestionScreen/buttonResult2.png"));
                    }
                    else
                    {
                        NextButtonImage = new BitmapImage(new Uri("pack://application:,,,/Content/QuestionScreen/buttonDown2.png"));
                    }
                }
                else
                {
                    CurrentChoices.Clear();
                    FirstLayoutVisibility = Visibility.Visible;//Change FirstLayoutVisibility will change SecondLayoutVisibility automatically
                    for (int i = 0; i < CurrentQuestion.ChoiceCount; i++)
                    {
                        var ktb = new KinectTileButton();
                        ktb.Tag = i;


                        ktb.HorizontalLabelAlignment = HorizontalAlignment.Center;
                        ktb.VerticalLabelAlignment   = VerticalAlignment.Center;

                        ktb.Click += ktb_Click;

                        ktb.Width  = ButtonWidth;
                        ktb.Height = ButtonWidth / 1.5;

                        //ktb.LabelBackground =new SolidColorBrush( );
                        ktb.BorderThickness = new Thickness(0, 0, 0, 0);

                        ktb.Label = CurrentQuestion.Answers[i].Text;

                        ImageSource frameSource = new BitmapImage(new Uri("pack://application:,,,/Content/QuestionScreen/frame.png"));
                        Image       frame       = new Image();

                        frame.Source  = frameSource;
                        frame.Stretch = Stretch.Fill;
                        ktb.Content   = frame;

                        double margin = ((RightScrollLen * 2 - CurrentQuestion.ChoiceCount * ButtonWidth) /
                                         CurrentQuestion.ChoiceCount) / 2;
                        margin = margin - margin / 4;

                        ktb.Margin = new Thickness(margin, 0, margin, 0);

                        ImageBrush backBrush;
                        if (CurrentQuestion.Answers[i].AttachImage != null)
                        {
                            ktb.VerticalLabelAlignment = VerticalAlignment.Bottom;

                            //ktb.Height = img.Height;
                            backBrush = new ImageBrush(CurrentQuestion.Answers[i].AttachImage);
                        }
                        else
                        {
                            backBrush = new ImageBrush(new BitmapImage(new Uri(
                                                                           "pack://application:,,,/Content/QuestionScreen/answerbg" + (i + 1) + ".png")));
                            backBrush.Opacity = 0.4;
                        }
                        backBrush.Stretch = Stretch.Fill;
                        ktb.Background    = backBrush;
                        CurrentChoices.Add(ktb);
                    }
                    if (CurrentIndex == EachTimeQuestionsCount)
                    {
                        NextButtonImage = new BitmapImage(new Uri("pack://application:,,,/Content/QuestionScreen/buttonResult.png"));
                    }
                    else
                    {
                        NextButtonImage = new BitmapImage(new Uri("pack://application:,,,/Content/QuestionScreen/buttonDown.png"));
                    }
                }
            }
            else
            {
                NavigationManager.NavigateToHome(DefaultNavigableContexts.ResultScreen);
            }
        }