public void Output(IEnumerable<ColorTextPair> sourcePairs, IEnumerable<ColorTextPair> textPairs) { if (Document == null || DocumentScrollViewer == null) return; OutputCount++; if (OutputCount > OUTPUT_MAX_LINES) Document.Blocks.Remove(Document.Blocks.FirstBlock); string timeStamp; timeStamp = DateTime.Now.ToString(ZChat.Options.TimeStampFormat); TimeSourceTextGroup group = new TimeSourceTextGroup(timeStamp, sourcePairs, textPairs); Dispatcher.BeginInvoke(new VoidDelegate(delegate { AddOutput(group); if (VisualTreeHelper.GetChildrenCount(DocumentScrollViewer) > 0) { DependencyObject DO = VisualTreeHelper.GetChild(DocumentScrollViewer, 0); while (!(DO is ScrollViewer)) DO = VisualTreeHelper.GetChild(DO, 0); ScrollViewer sv = DO as ScrollViewer; if (sv.VerticalOffset == sv.ScrollableHeight) sv.ScrollToBottom(); } })); }
public void AddOutput(TimeSourceTextGroup group) { Paragraph p = new Paragraph(); p.Padding = paragraphPadding; p.TextAlignment = TextAlignment.Left; Span timeSourceSpan = new Span(); Run timeRun = new Run(group.Time); timeRun.Foreground = ZChat.Options.TimeFore; p.Inlines.Add(timeRun); List<ColorTextPair> allPairs = new List<ColorTextPair>(); allPairs.AddRange(group.Source); allPairs.Add(new ColorTextPair(ZChat.Options.TextFore, " ")); allPairs.AddRange(group.Text); AddInlines(p.Inlines, allPairs, true); double indent = new FormattedText(timeRun.Text + PairsToPlainText(group.Source) + "W", System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(Document.FontFamily, Document.FontStyle, Document.FontWeight, Document.FontStretch), 12.0, Brushes.Black).Width; p.Margin = new Thickness(indent, 0.0, 0.0, 0.0); p.TextIndent = indent * -1; Document.Blocks.Add(p); }