protected override void OnRender(DrawingContext drawingContext) { _textBlock.Inlines.Clear(); if (FormattedText == null || !FormattedText.Any()) { if (Text != null) { _textBlock.Inlines.Add(Text); } base.OnRender(drawingContext); return; } var formattedText = FormattedText.AsArray(); if (formattedText.Length == 1) { var line = formattedText[0]; _textBlock.Text = line.Text; //if (line.Highlight && HighlightEnabled) //{ // if (line.Hue == Hue.NotSpecified) // { // _textBlock.Background = this.HighlightBackgroundBrush; // _textBlock.Foreground = this.HighlightForegroundBrush; // } // else // { // _textBlock.Background = line.Hue.BackgroundBrush; // _textBlock.Foreground = line.Hue.ForegroundBrush; // } //} } else { _textBlock.Inlines.AddRange(formattedText.Select(ft => { var run = new Run(ft.Text); if (ft.Highlight && HighlightEnabled) { if (ft.Hue == Hue.NotSpecified) { run.Background = HighlightBackgroundBrush; run.Foreground = HighlightForegroundBrush; } else { run.Background = ft.Hue.BackgroundBrush; run.Foreground = ft.Hue.ForegroundBrush; } } return(run); })); } base.OnRender(drawingContext); }
protected override void OnRender(DrawingContext drawingContext) { _textBlock.Inlines.Clear(); if (FormattedText == null || !FormattedText.Any()) { if (Text != null) { _textBlock.Inlines.Add(Text); } base.OnRender(drawingContext); return; } _textBlock.Inlines.AddRange(FormattedText.Select(ft => { var run = new Run(ft.Text); if (ft.Highlight && HighlightEnabled) { if (HighlightBackground != null) { run.Background = HighlightBackground; } if (HighlightForeground != null) { run.Foreground = HighlightForeground; } run.FontWeight = FontWeights.Bold; } return(run); })); base.OnRender(drawingContext); }