Beispiel #1
0
        private void OnLogChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_previousServerLog == null)
            {
                return;
            }

            var textView      = Text.TextArea.TextView;
            var needsToScroll = textView.VerticalOffset + textView.ActualHeight + 1 >= textView.DocumentHeight;

            if (e.Action == NotifyCollectionChangedAction.Add)
            {
                Text.Document.BeginUpdate();
                foreach (var item in e.NewItems.OfType <string>())
                {
                    Text.Document.Insert(Text.Document.TextLength, "\n");
                    Text.Document.Insert(Text.Document.TextLength, item);
                }
                Text.Document.EndUpdate();
            }
            else
            {
                Text.Document.Text = _previousServerLog.JoinToString("\n");
            }
            if (needsToScroll)
            {
                Text.ScrollToEnd();
            }
        }