Beispiel #1
0
        private void ShowPowerExponentPart()
        {
            if (this.powerExponentPart == null)
            {
                return;
            }

            this.baseNumberPanel.Children.Clear();
            this.powerPanel.Children.Clear();

            CommonControlCreator.CreateContentControl(this.powerExponentPart.BaseNumber, this.baseNumberPanel, this.Foreground, null);
            CommonControlCreator.CreateContentControl(this.powerExponentPart.Power.Content, this.powerPanel, this.Foreground, null);
        }
Beispiel #2
0
        private void ShowFractionPart()
        {
            if (this.fractionPart == null)
            {
                return;
            }

            if (this.fractionPart.WithPart != null)
            {
                this.withPanel.Visibility = System.Windows.Visibility.Visible;
                CommonControlCreator.CreateContentControl(this.fractionPart.WithPart, this.withPanel, this.Foreground, null);
            }
            else
            {
                this.withPanel.Visibility = System.Windows.Visibility.Hidden;
            }

            CommonControlCreator.CreateContentControl(this.fractionPart.Numerator, this.umeratorPanel, this.Foreground, null);
            CommonControlCreator.CreateContentControl(this.fractionPart.Denominator, this.denominatorPanel, this.Foreground, null);
        }
Beispiel #3
0
        public static Panel CreateContentControl(QuestionContent content, Panel contentPanel, Brush foreground, ContentPartCreated contentPartCreated)
        {
            Panel stackPanel = contentPanel;

            if (stackPanel == null)
            {
                stackPanel = new StackPanel();
                ((StackPanel)stackPanel).Orientation = Orientation.Vertical;
            }

            string questionContent = content.Content;

            if (string.IsNullOrEmpty(questionContent))
            {
                return(stackPanel);
            }

            int        startIndex = 0;
            StackPanel itemPanel  = new StackPanel();

            itemPanel.Orientation = Orientation.Horizontal;
            stackPanel.Children.Add(itemPanel);
            bool newLine = false;

            while (true)
            {
                startIndex = questionContent.IndexOf("_$", 0);
                if (startIndex >= 0)
                {
                    int    endIndex    = questionContent.IndexOf("$_", startIndex);
                    string placeHolder = questionContent.Substring(startIndex, endIndex - startIndex + 2);

                    string text = questionContent.Substring(0, startIndex);

                    if (!string.IsNullOrEmpty(text))
                    {
                        string[] textParts = text.Split(new char[] { '\n' });
                        if (textParts.Length > 1)
                        {
                            for (int i = 0; i < textParts.Length; i++)
                            {
                                string temp = textParts[i];
                                itemPanel.Children.Add(CreateText(temp, foreground));

                                if (i == textParts.Length - 1)
                                {
                                    break;
                                }

                                StackPanel nextItemPanel = new StackPanel();
                                nextItemPanel.Orientation = Orientation.Horizontal;
                                stackPanel.Children.Add(nextItemPanel);
                                itemPanel = nextItemPanel;
                            }
                        }
                        else
                        {
                            itemPanel.Children.Add(CreateText(text, foreground));
                        }
                    }
                    //else
                    //{
                    //    string[] textParts = text.Split(new char[] { '\n' });
                    //    if (textParts.Length > 1)
                    //    {
                    //        foreach (string temp in textParts)
                    //        {
                    //            itemPanel.Children.Add(CreateText(temp));

                    //            StackPanel nextItemPanel = new StackPanel();
                    //            nextItemPanel.Orientation = Orientation.Horizontal;
                    //            stackPanel.Children.Add(nextItemPanel);
                    //            itemPanel = nextItemPanel;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        itemPanel.Children.Add(CreateText(text));
                    //    }
                    //}

                    if (newLine)
                    {
                        StackPanel nextItemPanel = new StackPanel();
                        nextItemPanel.Orientation = Orientation.Horizontal;
                        stackPanel.Children.Add(nextItemPanel);
                        itemPanel = nextItemPanel;
                    }

                    newLine = false;

                    QuestionContentPart part    = content.GetContentPart(placeHolder);
                    UIElement           element = CommonControlCreator.CreateUIPart(part, foreground);
                    itemPanel.Children.Add(element);
                    if (contentPartCreated != null)
                    {
                        contentPartCreated(element);
                    }

                    questionContent = questionContent.Remove(0, endIndex + 2);
                    if (string.IsNullOrEmpty(questionContent))
                    {
                        break;
                    }
                }
                else
                {
                    string[] textParts = questionContent.Split(new char[] { '\n' });
                    foreach (string text in textParts)
                    {
                        itemPanel.Children.Add(CreateText(text, foreground));

                        StackPanel nextItemPanel = new StackPanel();
                        nextItemPanel.Orientation = Orientation.Horizontal;
                        stackPanel.Children.Add(nextItemPanel);
                        itemPanel = nextItemPanel;
                    }

                    break;
                }
            }

            return(stackPanel);
        }