C# 富文本框/流程文档>;格式(列表顺序、行距和项目符号)
我在WPF应用程序中有一个C# 富文本框/流程文档>;格式(列表顺序、行距和项目符号),c#,wpf,richtextbox,C#,Wpf,Richtextbox,我在WPF应用程序中有一个RichTextBox,用作状态更新的输出容器。添加的每一行都根据其信息级别(警告黄色、信息灰色等)上色 虽然技术上可行,但经过数小时的挖掘,我仍然有一些格式问题,我似乎无法克服或研究出来: 我想把清单倒过来,最新的“帖子”放在最上面。我已经通过几种不同的方法实现了这一点,但每种方法都要以将以前的颜色格式转换为控件的默认前景色为代价(当间距非常理想时,应用程序有一个大约10行的视觉缓冲区,需要保留应用的颜色) 我希望行距是正常的,行间没有填充。在使用列表时,每个“帖子”
RichTextBox
,用作状态更新的输出容器。添加的每一行都根据其信息级别(警告黄色、信息灰色等)上色
虽然技术上可行,但经过数小时的挖掘,我仍然有一些格式问题,我似乎无法克服或研究出来:
提前感谢。我发现一些属性可以让我实现这一点,所以我删除了列表,经过一些调整后,我得出了以下结论:
// Status Update
public void UpdateStatus(string eventLevel, string message)
{
Paragraph currentStatus = new Paragraph(new Run(message));
if (eventLevel == "info")
currentStatus.Foreground = System.Windows.Media.Brushes.Gray;
if (eventLevel == "warning")
currentStatus.Foreground = System.Windows.Media.Brushes.Yellow;
if (eventLevel == "error")
currentStatus.Foreground = System.Windows.Media.Brushes.Red;
if (eventLevel == "highlight")
currentStatus.Foreground = System.Windows.Media.Brushes.CornflowerBlue;
currentStatus.LineHeight = 1;
rtbStatus.Document.Blocks.InsertBefore(rtbStatus.Document.Blocks.FirstBlock, currentStatus);
}
现在可以在“顶部”添加彩色线条,线条间距最小:
UpdateStatus("error", "My custom error message");
为什么不切换到
TextBlock
s的ListBox
?或者甚至是一个DataGrid
,这样您就可以按日期、严重程度或其他什么对事件进行排序了?
UpdateStatus("error", "My custom error message");