private void OnQuestonCtrlSelectedChanged(object sender, EventArgs e)
        {
            Question_a_b_c_Control preCtrl = this.ActiveQuestionControl;

            if (preCtrl != null)
            {
                preCtrl.ValidResult();
                this.questionData.AutoSave();
            }

            Question_a_b_c_Control ctrl = sender as Question_a_b_c_Control;

            if (ctrl == null)
            {
                return;
            }

            if (ctrl.IsSelected)
            {
                this.ActiveQuestionControl = ctrl;
                if (!this.openVirtualKeyboardCheckBox.IsChecked.Value)
                {
                    return;
                }

                int index = this.questionGrid.Children.IndexOf(ctrl);

                this.numberKeyboardPopup.IsOpen          = false;
                this.numberKeyboardPopup.Placement       = System.Windows.Controls.Primitives.PlacementMode.Right;
                this.numberKeyboardPopup.PlacementTarget = ctrl;
                this.numberKeyboardPopup.IsOpen          = true;
            }
        }
        private void UpdatePageInfo()
        {
            this.ActiveQuestionControl = (Question_a_b_c_Control)this.questionGrid.Children[0];
            if (this.ActiveQuestionControl != null)
            {
                this.ActiveQuestionControl.Select();
            }

            if (this.totalPage == 1)
            {
                this.prePage.Visibility  = System.Windows.Visibility.Hidden;
                this.nextPage.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                if (this.currentPage == 0)
                {
                    this.prePage.Visibility  = System.Windows.Visibility.Hidden;
                    this.nextPage.Visibility = System.Windows.Visibility.Visible;
                }
                else if (this.currentPage == this.totalPage - 1)
                {
                    this.prePage.Visibility  = System.Windows.Visibility.Visible;
                    this.nextPage.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    this.prePage.Visibility  = System.Windows.Visibility.Visible;
                    this.nextPage.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }
        private void SafeGeneratedQuestionCompleted(int index)
        {
            this.CreateQuestionControl();

            this.questionData.AutoSave();

            this.ShowGeneratingInfo(false);

            this.timeControl              = new TimeControlEngine();
            this.timeControl.TimeElapsed += new EventHandler(timeControl_TimeElapsed);

            this.timerPanel.Visibility = System.Windows.Visibility.Visible;

            this.timeControl.Start();

            int i = 0;

            foreach (Question_a_b_c_Control ctrl in this.questionGrid.Children)
            {
                if (ctrl == null)
                {
                    continue;
                }

                if (ctrl.DataContext is Question_a_b_c)
                {
                    Question_a_b_c oldQ = ctrl.DataContext as Question_a_b_c;
                    oldQ.PropertyChanged -= q_PropertyChanged;
                }

                Question_a_b_c q = this.questionData.Items[i++] as Question_a_b_c;
                ctrl.DataContext   = q;
                q.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(q_PropertyChanged);
                if (i == this.questionData.Items.Count)
                {
                    break;
                }

                ctrl.SelectedChanged   += OnQuestonCtrlSelectedChanged;
                ctrl.QuestionValidated += OnQuestionValidated;
            }

            this.ActiveQuestionControl = (Question_a_b_c_Control)this.questionGrid.Children[0];
            if (this.ActiveQuestionControl != null)
            {
                this.ActiveQuestionControl.Select();
            }

            this.currentPage = 0;
            this.totalPage   = this.questionData.Items.Count / MathSetting.Instance.QuestionCountPerPage;
            if (this.questionData.Items.Count % MathSetting.Instance.QuestionCountPerPage != 0)
            {
                this.totalPage++;
            }

            //   this.countPerPageLabel.Content = string.Format(SoonLearning.Math.Fast.Properties.Resources.questionCountPerPage, MathSetting.Instance.QuestionCountPerPage);
            //this.Total = this.totalPage;
            this.UpdatePageInfo();
        }
Ejemplo n.º 4
0
        protected virtual Control CreateQuestionControl(float fontSize, FontWeight weight)
        {
            Question_a_b_c_Control abcCtrl = new Question_a_b_c_Control(fontSize, weight, this.abColumeWidth);

            abcCtrl.VerticalAlignment   = VerticalAlignment.Center;
            abcCtrl.HorizontalAlignment = HorizontalAlignment.Center;
            return(abcCtrl);
        }
        private void numberKeyboard_NumberVirtualKeyboardInputEvent(Key key)
        {
            if (key == Key.Enter)
            {
                this.EnterPressed();
                return;
            }

            if (this.numberKeyboardPopup.PlacementTarget is Question_a_b_c_Control)
            {
                Question_a_b_c_Control ctrl = this.numberKeyboardPopup.PlacementTarget as Question_a_b_c_Control;
                ctrl.numberKeyboard_NumberVirtualKeyboardInputEvent(key);
            }
        }
        private void EnterPressed()
        {
            int index = 0;
            Question_a_b_c_Control currentCtrl = this.activeQuestionCtrl;

            foreach (Question_a_b_c_Control ctrl in this.questionGrid.Children)
            {
                if (ctrl == null)
                {
                    continue;
                }

                if (ctrl == currentCtrl)
                {
                    break;
                }
                index++;
            }

            if (currentCtrl != null)
            {
                currentCtrl.IsSelected = false;
            }

            if (index == this.questionGrid.Children.Count - 1)
            {
                this.nextPage_Click(this, null);
            }
            else
            {
                index++;
                if (this.currentPage + 1 == this.totalPage)
                {
                    if (MathSetting.Instance.QuestionCountPerPage * this.currentPage + index == this.questionData.Items.Count)
                    {
                        return;
                    }
                }

                if (index < this.questionGrid.Children.Count)
                {
                    this.ActiveQuestionControl = (Question_a_b_c_Control)this.questionGrid.Children[index];
                    if (this.ActiveQuestionControl != null)
                    {
                        this.ActiveQuestionControl.Select();
                    }
                }
            }
        }
        private void UserControl_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            base.OnPreviewKeyDown(e);

            switch (e.Key)
            {
            case Key.Enter:
                this.EnterPressed();
                break;

            case Key.Up:
            {
                int index = 0;
                foreach (Question_a_b_c_Control ctrl in this.questionGrid.Children)
                {
                    if (ctrl == null)
                    {
                        continue;
                    }

                    if (ctrl == this.ActiveQuestionControl)
                    {
                        ctrl.IsSelected = false;
                        break;
                    }
                    index++;
                }

                if (this.currentPage + 1 == this.totalPage)
                {
                    if (index == 0)
                    {
                        index = this.questionData.Items.Count - this.currentPage * MathSetting.Instance.QuestionCountPerPage - 1;
                    }
                    else
                    {
                        index--;
                    }
                }
                else
                {
                    if (index == 0)
                    {
                        index = this.questionGrid.Children.Count - 1;
                    }
                    else
                    {
                        index--;
                    }
                }

                this.ActiveQuestionControl = (Question_a_b_c_Control)this.questionGrid.Children[index];
                if (this.ActiveQuestionControl != null)
                {
                    this.ActiveQuestionControl.Select();
                }
            }
            break;

            case Key.Down:
            {
                int index = 0;
                foreach (Question_a_b_c_Control ctrl in this.questionGrid.Children)
                {
                    if (ctrl == null)
                    {
                        continue;
                    }

                    if (ctrl == this.ActiveQuestionControl)
                    {
                        ctrl.IsSelected = false;
                        break;
                    }
                    index++;
                }

                if (this.currentPage + 1 == this.totalPage)
                {
                    if (MathSetting.Instance.QuestionCountPerPage * this.currentPage + index == this.questionData.Items.Count - 1)
                    {
                        index = 0;
                    }
                    else
                    {
                        index++;
                    }
                }
                else
                {
                    if (index == this.questionGrid.Children.Count - 1)
                    {
                        index = 0;
                    }
                    else
                    {
                        index++;
                    }
                }

                this.ActiveQuestionControl = (Question_a_b_c_Control)this.questionGrid.Children[index];
                if (this.ActiveQuestionControl != null)
                {
                    this.ActiveQuestionControl.Select();
                }
            }
            break;

            case Key.Left:
                this.prePage_Click(this, null);
                break;

            case Key.Right:
                this.nextPage_Click(this, null);
                break;
            }
        }