Esempio n. 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, null);
            CommonControlCreator.CreateContentControl(this.powerExponentPart.Power.Power, this.powerPanel, null);
        }
Esempio n. 2
0
        internal static Panel CreateContentControl(QuestionContent content, Panel contentPanel, 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));

                                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));
                        }
                    }
                    //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);
                    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));

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

                    break;
                }
            }

            return(stackPanel);
        }