/// <summary> /// Set part of Dependency property/ /// </summary> public static void SetEmoticonsConverter(DependencyObject obj, IEmoticonsConverter value) { obj.SetValue(EmoticonsConverterProperty, value); }
private static void textbox_Loaded(object sender, RoutedEventArgs e) { var textBlock = sender as TextBlock; textBlock.Loaded -= textbox_Loaded; IEmoticonsConverter emoticonsConverter = null; lock (_lock) { emoticonsConverter = _emoticonsConverters[textBlock]; _emoticonsConverters.Remove(textBlock); } var text = textBlock.Text; textBlock.Inlines.Clear(); StringBuilder sb = new StringBuilder(); string pom = string.Empty; for (int i = 0; i < text.Length; i++) { if (!pom.IsNullOrWhiteSpace() && pom.Length == 3) { if (emoticonsConverter.IsEmoticonAlias(pom)) { var image = new Image() { Source = emoticonsConverter.Emoticon(pom), Stretch = System.Windows.Media.Stretch.UniformToFill, Width = textBlock.FontSize, Height = textBlock.FontSize }; textBlock.Inlines.Add(new Run(sb.ToString())); sb = new StringBuilder(); pom = string.Empty; RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality); textBlock.Inlines.Add(new InlineUIContainer(image)); } else { } } pom = text.Substring(i, 1); } //var text = textBlock.Text; //textBlock.Inlines.Clear(); //while (text.Contains(":-)")) //{ // textBlock.Inlines.Add(new Run(text.Substring(0, text.IndexOf(":-)")))); // text = text.Substring(text.IndexOf(":-)") + 3); // var image = new Image() // { // Source = Emoticon(), // Stretch = System.Windows.Media.Stretch.UniformToFill, // Width = textBlock.FontSize, // Height = textBlock.FontSize // }; // RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality); // textBlock.Inlines.Add(new InlineUIContainer(image)); //} //if (!text.IsNullOrEmpty()) //{ // textBlock.Inlines.Add(new Run(text)); //} //var text = textBlock.Text; //textBlock.Inlines.Clear(); //IList<string> sb = new List<string>(); //foreach (string word in text.SplitBySeparator(" ")) //{ // if (emoticonsConverter.IsEmoticonAlias(word)) // { // if (sb.Count > 0) // { // textBlock.Inlines.Add(new Run(sb.ToArray().JoinToString(" "))); // } // sb = new List<string>(); // var image = new Image() // { // Source = emoticonsConverter.Emoticon(word), // Stretch = System.Windows.Media.Stretch.UniformToFill, // Width = textBlock.FontSize, // Height = textBlock.FontSize // }; // RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.HighQuality); // textBlock.Inlines.Add(new InlineUIContainer(image)); // } // else // { // sb.Add(word); // } //} //if (sb.Count > 0) //{ // textBlock.Inlines.Add(new Run(sb.ToArray().JoinToString(" "))); //} }
private void Neviem(TextBlock textblock, string text, IEmoticonsConverter converter) { }