internal static Paragraph CreateContentControl(QuestionContent content, string prefix, Paragraph paragraph, Response response)
        {
            Paragraph section = paragraph;

            if (section == null)
            {
                section = new Paragraph();
            }

            string questionContent = content.Content;
            int    startIndex      = 0;

            section.Inlines.Add(prefix);
            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) &&
                        text[text.Length - 1] == '\n')
                    {
                        section.Inlines.Add(CreateText(text.Remove(text.Length - 1)));
                    }
                    else
                    {
                        section.Inlines.Add(CreateText(text));
                    }

                    QuestionContentPart part = content.GetContentPart(placeHolder);
                    if (response is FIBQuestionResponse)
                    {
                        FIBQuestionResponse fibResponse = response as FIBQuestionResponse;
                        section.Inlines.Add(CreateUIPart(part, fibResponse.GetBlankResponse(part.Id, false)));
                    }
                    else
                    {
                        section.Inlines.Add(CreateUIPart(part, null));
                    }

                    questionContent = questionContent.Remove(0, endIndex + 2);
                    if (string.IsNullOrEmpty(questionContent))
                    {
                        break;
                    }
                }
                else
                {
                    section.Inlines.Add(CreateText(questionContent));
                    break;
                }
            }

            return(section);
        }
        internal static System.Windows.Documents.Section CreateContentControl(QuestionContent content, string prefix, System.Windows.Documents.Section paragraph, Response response)
        {
            System.Windows.Documents.Section rootSection = paragraph;
            if (rootSection == null)
            {
                rootSection = new System.Windows.Documents.Section();
            }

            if (content.ContentType == ContentType.Html ||
                content.ContentType == ContentType.FlowDocument)
            {
                string doc = string.Empty;
                if (content.ContentType == ContentType.Html)
                {
                    doc = HtmlToXamlConverter.ConvertHtmlToXaml(content.Content, true);
                }
                else
                {
                    doc = content.Content;
                }

                System.Windows.Documents.FlowDocument flowDocument = HtmlToXamlConverter.DeserializeFlowDocument(doc);

                replaceTextBoxWithText(flowDocument, content, null);

                List <Block> tempList = new List <Block>();
                tempList.AddRange(flowDocument.Blocks);
                flowDocument.Blocks.Clear();
                rootSection.Blocks.AddRange(tempList);

                Paragraph firstPara = null;
                if (rootSection.Blocks.FirstBlock is Paragraph)
                {
                    firstPara = rootSection.Blocks.FirstBlock as Paragraph;
                }
                else
                {
                    firstPara = new Paragraph();
                    rootSection.Blocks.InsertBefore(rootSection.Blocks.FirstBlock, firstPara);
                }

                if (firstPara.Inlines.Count > 0)
                {
                    firstPara.Inlines.InsertBefore(firstPara.Inlines.FirstInline, new Run(prefix));
                }
                else
                {
                    firstPara.Inlines.Add(prefix);
                }
            }
            else
            {
                Paragraph para = null;
                if (rootSection.Blocks.LastBlock is Paragraph)
                {
                    para = rootSection.Blocks.LastBlock as Paragraph;
                }
                else
                {
                    para = new Paragraph();
                    rootSection.Blocks.Add(para);
                }

                string questionContent = content.Content;
                int    startIndex      = 0;

                para.Inlines.Add(prefix);

                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) &&
                            text[text.Length - 1] == '\n')
                        {
                            para.Inlines.Add(CreateText(text.Remove(text.Length - 1)));
                        }
                        else
                        {
                            para.Inlines.Add(CreateText(text));
                        }

                        QuestionContentPart part = content.GetContentPart(placeHolder);
                        if (response is FIBQuestionResponse)
                        {
                            FIBQuestionResponse fibResponse = response as FIBQuestionResponse;
                            para.Inlines.Add(CreateUIPart(part, fibResponse.GetBlankResponse(part.Id, false)));
                        }
                        else
                        {
                            para.Inlines.Add(CreateUIPart(part, null));
                        }

                        questionContent = questionContent.Remove(0, endIndex + 2);
                        if (string.IsNullOrEmpty(questionContent))
                        {
                            break;
                        }
                    }
                    else
                    {
                        para.Inlines.Add(CreateText(questionContent));
                        break;
                    }
                }
            }

            return(rootSection);
        }