private static Brush GetBackground(IOutputLine e) { // Setup initial conditions. var defaultColor = default(Color); var color = e.Color; if (Equals(color, defaultColor)) return null; // Set opacity of color (only adjust if the color does not already contain an opacity value). if (color.A == 255) color.A = 20; // Finish up. return new SolidColorBrush(color); }
private static string ToText(IOutputLine line) { if (line == null || line.Value == null) return null; return line.Value.ToString(); }
private void Write(IOutputLine e) { // Setup initial conditions. if (!Control.IsActive) return; Count++; // Update the collection. var line = new OutputLineViewModel { Parent = this, LineNumber = Count, Created = DateTime.Now, Text = ToText(e), FontWeight = e.FontWeight, Background = GetBackground(e), DividerColor = dividerColor, }; lock (Lines) { Lines.Add(line); } // Update visual state. UpdateVisualState(); // Scroll to bottom item. ScrollToBottom(); scrollDelay.Start(); // NB: Ensure scroll is moved to the bottom if multiple calls made before redraw. }