public static UIElement CreateUIPart(QuestionContentPart part) { if (part is QuestionBlank) { NumberOnlyTextBox blankTextBox = new NumberOnlyTextBox(); blankTextBox.Tag = part; blankTextBox.Width = 80; blankTextBox.VerticalAlignment = System.Windows.VerticalAlignment.Center; blankTextBox.FontSize = 20; blankTextBox.Margin = new Thickness(1); return(blankTextBox); } else if (part is ArithmeticDecimalValuePart) { ArithmeticDecimalValuePart decimalPart = part as ArithmeticDecimalValuePart; if (decimalPart.Value == null) { return(CreateText(string.Empty)); } return(CreateText(decimalPart.Value.ToString())); } else if (part is ArithmeticFractionValuePart) { ArithmeticFractionValuePart fractionPart = part as ArithmeticFractionValuePart; FractionControl fractionControl = new FractionControl(20, FontWeights.Medium, 2, new SolidColorBrush(Colors.Black)); fractionControl.Numerator = fractionPart.Numerator; fractionControl.Denominator = fractionPart.Denominator; fractionControl.FontSize = 20; fractionControl.FontWeight = FontWeights.Medium; fractionControl.VerticalAlignment = VerticalAlignment.Center; return(fractionControl); } else if (part is ArithmeticSignPart) { } else if (part is QuestionTextPart) { QuestionTextPart textPart = part as QuestionTextPart; return(CreateText(textPart.Text)); } else if (part is QuestionPowerExponentPart) { PowerExponentControl powerExponentControl = new PowerExponentControl(20, FontWeights.Medium, new SolidColorBrush(Colors.Black)); powerExponentControl.PowerExponentPart = part as QuestionPowerExponentPart; return(powerExponentControl); } else if (part is QuestionPowerPart) { } else if (part is QuestionFlowDocumentPart) { } throw new NotSupportedException(); }
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); }
public static Inline CreateUIPart(QuestionContentPart part, Response response) { if (part is QuestionBlank) { if (response is QuestionBlankResponse) { QuestionBlankResponse blankResponse = response as QuestionBlankResponse; Paragraph blankPara = CreateContentControl(blankResponse.BlankContent, string.Empty, null, null); Span span = new Span(); span.Inlines.Add("( "); List <Inline> inlineList = new List <Inline>(); inlineList.AddRange(blankPara.Inlines); foreach (Inline inline in inlineList) { span.Inlines.Add(inline); } span.Inlines.Add(" )"); span.BaselineAlignment = BaselineAlignment.Center; return(span); } Run blankRun = new Run("( )"); blankRun.BaselineAlignment = BaselineAlignment.Center; return(blankRun); } else if (part is ArithmeticDecimalValuePart) { ArithmeticDecimalValuePart decimalPart = part as ArithmeticDecimalValuePart; if (decimalPart.Value == null) { return(CreateText(string.Empty)); } return(CreateText(decimalPart.Value.ToString())); } else if (part is ArithmeticFractionValuePart) { ArithmeticFractionValuePart fractionPart = part as ArithmeticFractionValuePart; return(CreateFraction(fractionPart)); } else if (part is ArithmeticSignPart) { } else if (part is QuestionTextPart) { QuestionTextPart textPart = part as QuestionTextPart; return(CreateText(textPart.Text)); } else if (part is QuestionFlowDocumentPart) { } throw new NotSupportedException(); }
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); }
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; } if (content.ContentType == ContentType.Html || content.ContentType == ContentType.FlowDocument) { FlowDocumentScrollViewer documentViewer = new FlowDocumentScrollViewer(); documentViewer.FocusVisualStyle = null; documentViewer.VerticalContentAlignment = VerticalAlignment.Center; documentViewer.VerticalAlignment = VerticalAlignment.Center; documentViewer.HorizontalContentAlignment = HorizontalAlignment.Left; documentViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; documentViewer.Background = Brushes.Transparent; documentViewer.FontSize = 20; FlowDocument document = null; if (content.ContentType == ContentType.Html) { document = HtmlToXamlConverter.ConvertHtmlToXaml(content.Content); } else { document = HtmlToXamlConverter.DeserializeFlowDocument(content.Content); } replaceTextBoxWithRichTextBox(document, content, contentPartCreated); document.FontSize = 20; documentViewer.Document = document; stackPanel.Children.Add(documentViewer); } else { 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); }
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); }