public static void OnPropertyChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs) { var itemProperty = (ItemLineContent)dependencyObject; itemProperty.RichText.Document.Blocks.Clear(); itemProperty.RichText.Document.Blocks.Add(new Paragraph(new Run(itemProperty.Property.Parsed))); // create textpointer translator var trans = new TextPointerTranslator(itemProperty.RichText.Document); // enumerate foreach (var value in itemProperty.Property.Values) { var matches = Highlight.Matches(value.Value); var offset = itemProperty.Property.Parsed.IndexOf(value.Value); // enumerate for (var i = 0; i < matches.Count; i++) { var info = matches[i]; var start = trans.GetTextPointer(info.Index + offset, false); var end = trans.GetTextPointer(info.Index + info.Value.Length + offset, false); if (start == null || end == null) { continue; } var range = new TextRange(start, end); if (range != null) { range.ApplyPropertyValue( TextElement.FontWeightProperty, FontWeight.FromOpenTypeWeight(700)); switch (value.Type) { case LineContentType.Simple: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.White); break; case LineContentType.Augmented: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.LightBlue); break; } } } } }
public static void OnItemChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs) { var filter = (Filter)dependencyObject; filter.RichText.Document.Blocks.Clear(); filter.RichText.Document.Blocks.Add(new Paragraph(new Run(filter.Item.Text))); filter.RichText.Foreground = filter.Item.Type == nameof(StatFilter) ? Brushes.White : Brushes.LightGray; var matches = Highlight.Matches(filter.Item.Text); // create textpointer translator var trans = new TextPointerTranslator(filter.RichText.Document); // enumerate for (var i = 0; i < matches.Count; i++) { var info = matches[i]; var start = trans.GetTextPointer(info.Index, false); var end = trans.GetTextPointer(info.Index + info.Value.Length, false); if (start == null || end == null) { continue; } var range = new TextRange(start, end); if (range != null) { range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.LightBlue); range.ApplyPropertyValue( TextElement.FontWeightProperty, FontWeight.FromOpenTypeWeight(700)); } } }
public static void OnPropertyChanged( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs) { var itemProperty = (ItemLineContent)dependencyObject; itemProperty.RichText.Document.Blocks.Clear(); itemProperty.RichText.Document.Blocks.Add(new Paragraph(new Run(itemProperty.Property.Parsed))); // create textpointer translator var trans = new TextPointerTranslator(itemProperty.RichText.Document); // enumerate foreach (var value in itemProperty.Property.Values) { var index = itemProperty.Property.Parsed.IndexOf(value.Value); var start = trans.GetTextPointer(index, false); var end = trans.GetTextPointer(index + value.Value.Length, false); if (start == null || end == null) { continue; } var range = new TextRange(start, end); if (range != null) { range.ApplyPropertyValue( TextElement.FontWeightProperty, FontWeight.FromOpenTypeWeight(700)); switch (value.Type) { case LineContentType.Simple: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.White); break; case LineContentType.Augmented: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.LightBlue); break; case LineContentType.Cold: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.LightSkyBlue); break; case LineContentType.Fire: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.DeepPink); break; case LineContentType.Lightning: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.LightYellow); break; case LineContentType.Chaos: range.ApplyPropertyValue( TextElement.ForegroundProperty, Brushes.Purple); break; } } } }