private void Redirect(StreamReader input, StreamReader inputError, TextBlock output) { output.Text = string.Empty; new Thread(a => { while (!input.EndOfStream) { var line = input.ReadLine(); output.Dispatcher.Invoke(new Action(delegate { output.Text += line + Environment.NewLine; ConsoleScroller.ScrollToBottom(); })); } ; }).Start(); new Thread(a => { while (!inputError.EndOfStream) { var line = inputError.ReadLine(); output.Dispatcher.Invoke(new Action(delegate { output.Text += line + Environment.NewLine; ConsoleScroller.ScrollToBottom(); })); } ; }).Start(); }
/// <summary> /// Scrolls to the bottom of the console window on update if already scrolled to the bottom. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The scroll changed event arguments.</param> private void ConsoleScroller_ScrollChanged(object sender, System.Windows.Controls.ScrollChangedEventArgs e) { if (ConsoleScroller.VerticalOffset == ConsoleScroller.ScrollableHeight && e.ExtentHeightChange != 0) { ConsoleScroller.ScrollToEnd(); } }
private void ItemsControl_SizeChanged(object sender, SizeChangedEventArgs e) { // Scroll to bottom only when the scroll is on the bottom if (ConsoleScroller.VerticalOffset == ConsoleScroller.ScrollableHeight) { ConsoleScroller.ScrollToBottom(); } }
private void ConsoleLog(string message) { OutputPanel.Children.Add(new TextBlock { Text = string.Format("{0}\n", message), TextWrapping = TextWrapping.Wrap }); ConsoleScroller.ScrollToVerticalOffset(OutputPanel.ActualHeight); //Keep scrollviewer scrolled to bottom (where new text appears) }
private void Logger_CustomLogging(LoggerArgs e) { if (e.Level <= _maxLogLevel) { // https://stackoverflow.com/a/18331866/1934487 uiContext.Post(x => { dc.ConsoleOutput.Add(e); //dc.ConsoleOutput.Add(bot.GetCurrentPosition().X); ConsoleScroller.ScrollToBottom(); }, null); } }
public void AddLine(string logItem) { try { TextBlock line = new TextBlock(); line.Text = logItem; line.Foreground = Brushes.White; Console.Children.Add(line); ConsoleScroller.ScrollToBottom(); } catch (Exception ex) { ErrorLogger.GenerateErrorRecord(ex); } }
public ConsoleLog(ObservableCollectionLoggerProvider loggerProvider) { InitializeComponent(); loggerProvider.LogBuffer.CollectionChanged += (s, e) => Dispatcher.Invoke(() => { if (e.Action == NotifyCollectionChangedAction.Add) { foreach (object item in e.NewItems) { ConsoleOutput.Add(item.ToString()); } ConsoleScroller.ScrollToBottom(); } }); }
public void Write(string msg, int level) { string color = "White"; if (level == 1) { color = "Yellow"; } else if (level == 0) { color = "Red"; } App.Current?.Dispatcher.Invoke(delegate { AllConsoleLogs.Add(new ConsoleEntry() { Text = msg, Color = color }); if (AllConsoleLogs.Count > MaxLogSize) { AllConsoleLogs.RemoveAt(0); } if (msg.IndexOf(FilterTextBox.Text) >= 0) { ConsoleLog.ConsoleOutput.Add(new ConsoleEntry() { Text = msg, Color = color }); if (ConsoleLog.ConsoleOutput.Count > MaxLogSize) { ConsoleLog.ConsoleOutput.RemoveAt(0); } } if (ConsoleScrollToBottom) { ConsoleScroller.ScrollToBottom(); } }); }
private void AddMessage(string message) { ConsoleMessagesField.Text += message + Environment.NewLine; ConsoleScroller.ScrollToEnd(); }
private void WriteToConsole(string text) { bigInputBuffer += text; if (bigInputBuffer.Length > BUFFER_LENGTH) { bigInputBuffer = bigInputBuffer.Substring(bigInputBuffer.Length - BUFFER_LENGTH); } _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { ConsoleView.Text = bigInputBuffer; ConsoleScroller.ChangeView(null, ConsoleScroller.ExtentHeight, null, true); }); }