I would use a RichTextBox control to output data.
In this example, I had no performance issues at all.
public partial class MainWindow : Window { private int counter = 0; public MainWindow() { InitializeComponent(); Loaded+=OnLoaded; } private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { for (int i = 0; i < 200; i++) { AddLine(counter++ + ": Initial data"); } var timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 200); timer.Tick += TimerOnTick; timer.IsEnabled = true; } private void TimerOnTick(object sender, EventArgs eventArgs) { AddLine(counter++ + ": Random text"); } public void AddLine(string text) { outputBox.AppendText(text); outputBox.AppendText("\u2028");
And xaml
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <RichTextBox x:Name="outputBox" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" IsReadOnly="True"> <FlowDocument/> </RichTextBox> </Grid> </Window>
And it is probably easy to extend. If the scroll position is not at the end, do not scroll to the end, for example, to view old data while the text field is still updating.
source share