private void SetEmojiText(string htmlFragment) { if (htmlFragment == null || htmlFragment.Length == 0) { return; } this.Blocks.Clear(); Paragraph paragraph; if (this.Blocks.Count == 0 || (paragraph = this.Blocks[this.Blocks.Count - 1] as Paragraph) == null) { paragraph = new Paragraph(); this.Blocks.Add(paragraph); } var nextOffset = 0; var regEx = new Regex(@"(\[emot=(?<emoji>.*?)/\])", RegexOptions.IgnoreCase | RegexOptions.Singleline); foreach (Match match in regEx.Matches(htmlFragment)) { if (match.Index == nextOffset) { nextOffset = match.Index + match.Length; if (match.Groups["emoji"].Value.Split(',').Count() > 1) { var grid = new Grid(); grid.Background = new SolidColorBrush(Colors.White); grid.Margin = new Thickness(1, 0, 1, 0); var image = new Image(); var bi = new BitmapImage(new Uri("/Assets/Emoji/" + match.Groups["emoji"].Value.Split(',')[0] + "/" + match.Groups["emoji"].Value.Split(',')[1] + ".png", UriKind.RelativeOrAbsolute)); image.Source = bi; image.Height = 60; grid.Children.Add(image); var container = new InlineUIContainer(); container.Child = grid; paragraph.Inlines.Add(container); } else { this.SetAtText(HtmlHelp.NoHTML(match.Groups["emoji"].Value)); } } else if (match.Index > nextOffset) { this.SetAtText(HtmlHelp.NoHTML(htmlFragment.Substring(nextOffset, match.Index - nextOffset))); nextOffset = match.Index + match.Length; if (match.Groups["emoji"].Value.Split(',').Count() > 1) { var grid = new Grid(); grid.Background = new SolidColorBrush(Colors.White); grid.Margin = new Thickness(1, 0, 1, 0); var image = new Image(); var bi = new BitmapImage(new Uri("/Assets/Emoji/" + match.Groups["emoji"].Value.Split(',')[0] + "/" + match.Groups["emoji"].Value.Split(',')[1] + ".png", UriKind.RelativeOrAbsolute)); image.Source = bi; image.Height = 60; grid.Children.Add(image); var container = new InlineUIContainer(); container.Child = grid; paragraph.Inlines.Add(container); } else { this.SetAtText(HtmlHelp.NoHTML(match.Groups["emoji"].Value)); } } } if (nextOffset < htmlFragment.Length) { this.SetAtText(HtmlHelp.NoHTML(htmlFragment.Substring(nextOffset))); } }