private async System.Threading.Tasks.Task FillRichTextBox(string text) { var start = 0; var regex = new Regex("(\\$[^\\$]+?\\$)|(\\$\\$[^\\$]+?\\$\\$)"); var paragraph = new Paragraph(); foreach (Match match in regex.Matches(text)) { var matchVal = match.Value; var notInline = matchVal.StartsWith("$$"); var imageId = notInline ? match.Value.Substring(3, match.Value.Length - 6) : match.Value.Substring(2, match.Value.Length - 4); paragraph.AddText(start, match.Index, text); if (notInline) { MathQuestionBox.Blocks.Add(paragraph); var imgParagraph = new Paragraph(); await imgParagraph.ReplaceLabelWithLargeImage(imageId); MathQuestionBox.Blocks.Add(imgParagraph); paragraph = new Paragraph(); } else { await paragraph.ReplaceLabelWithImage(imageId); } start = match.Index + match.Length; } paragraph.AddText(start, text.Length, text); //App.ViewModel.Blocks.Add(paragraph); MathQuestionBox.Blocks.Add(paragraph); }