Open
Description
Is your feature request related to a problem? Please describe.
In order to get better performance compared to RichTextBox, I display a FlowDocumentScrollViewer with a binding to a FlowDocument of the ViewModel.
<FlowDocumentScrollViewer Document="{Binding FlowDocument1}"
Loaded="FlowDocumentScrollViewer_Loaded"
Unloaded="FlowDocumentScrollViewer_Unloaded">
</FlowDocumentScrollViewer>
Describe the solution you'd like
I'd like a simple:
<FlowDocumentScrollViewer Document="{Binding FlowDocument1}"
Loaded="FlowDocumentScrollViewer_Loaded"
Unloaded="FlowDocumentScrollViewer_Unloaded"
Style="{StaticResource MaterialDesignFlowDocument}">
</FlowDocumentScrollViewer>
Describe alternatives you've considered
Here is the extension method dealing manually with style..
public static void AppendLogEvents(this FlowDocument flowDocument, IList<LogEvent> logEvents)
{
var lastParagraph = flowDocument.Blocks.LastBlock as Paragraph;
if (lastParagraph == null)
{
lastParagraph = new Paragraph();
flowDocument.Blocks.Add(lastParagraph);
}
// Create a new style based on the MaterialDesignTextBoxBase style
var spanStyle = new Style(typeof(Span));
//spanStyle.BasedOn = (Style)Application.Current.Resources["MaterialDesignTextBoxBase"];
//spanStyle.Setters.Add(new Setter(TextElement.FontSizeProperty, 7.0));
var materialDesignSourceStyle = (Style)Application.Current.Resources["MaterialDesignWindow"]; //MaterialDesignTextBlock
var materialDesignSourceStyle2 = (Style)Application.Current.Resources[typeof(MaterialDesignExtensions.Controls.MaterialWindow)];
// Transfer all properties to spanStyle
foreach (Setter setter in materialDesignSourceStyle.Setters.Union(materialDesignSourceStyle2.Setters))
spanStyle.Setters.Add(new Setter(setter.Property, setter.Value));
foreach (var logEvent in logEvents)
{
// Render log message with a template
var renderedMessage = logEvent.RenderMessage();
var span = new Span(new Run(renderedMessage));
span.Style = spanStyle; // Apply the new style to the Span
if (logEvent.Level == LogEventLevel.Warning)
span.Foreground = Brushes.Orange;
else if (logEvent.Level == LogEventLevel.Error || logEvent.Level == LogEventLevel.Fatal)
span.Foreground = Brushes.Red;
else { } //NTD, will let light/dark mode fontcolor
lastParagraph.Inlines.Add(span);
lastParagraph.Inlines.Add(Environment.NewLine);
}
}
Additional context
Add any other context or screenshots about the feature request here.
Any thing I missed?
Feel free to recommend another approach!
Regards,