为什么在添加新文本时,线条之间有空行?
private void Println(string text, SolidColorBrush brush) => Dispatcher.Invoke(() =>
{
RichTextBoxLogger.Document.Blocks.Add(new Paragraph(new Run(text) { Foreground = brush }));
});
private void Println(string text)
{
Println(text, Brushes.LawnGreen);
}
private void PrintMsg(string message)
{
Println($"[+] {message}", Brushes.Yellow);
}
private void PrintErr(Exception e)
{
Println($"[-] {e}", Brushes.Red);
}
使用它的
private void Fsw_Deleted(object sender, FileSystemEventArgs e)
{
string time = DateTime.Now.ToString("h:mm:ss tt");
string output = $"[*] {e.Name}: \"Deleted At : {time}\"";
Println(output);
}
结果是:
我想在它们之间没有空线的情况下添加此行。
private void Println(string text, SolidColorBrush brush) => Dispatcher.Invoke(() =>
{
RichTextBoxLogger.Document.Blocks.Add(new Paragraph(new Run(text) { Foreground = brush }));
});
private void Println(string text)
{
Println(text, Brushes.LawnGreen);
}
private void PrintMsg(string message)
{
Println(quot;[+] {message}", Brushes.Yellow);
}
private void PrintErr(Exception e)
{
Println(quot;[-] {e}", Brushes.Red);
}
Using it
private void Fsw_Deleted(object sender, FileSystemEventArgs e)
{
string time = DateTime.Now.ToString("h:mm:ss tt");
string output = quot;[*] {e.Name}: \"Deleted At : {time}\"";
Println(output);
}
The result is :
I want to add this lines without empty lines between them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了防止在两个连续的段落之间发生中断,您必须将
段落设置为
属性属性为true
:我不建议使用重型
richtextbox < /代码>用于您的任务。当输出生长时,它将变得慢。而是使用轻
ListBox
。ListBox
功能UI虚拟化,并将显着提高性能。当您将listBoxItem.ishittestvisible
设置为false
时,ListBox
看起来和感觉就像是只读文档。为每种消息类型定义一个数据表板,以控制输出的外观:ilogMessage.cs
errormessage.cs
红色消息。
parningmessage.cs
黄色消息。
infomessage.cs
绿色消息。
mainwindow.xaml.cs
mainwindow.xaml
strong 知道如何在添加新项目时将消息视图滚动到底部。您可以使用示例的
logmessagebox
控制(usercontrol
),然后替换上述ListBox
。To prevent a break from occurring between two consecutive paragraphs, you must set the
Paragraph.KeepWithNext
property totrue
:I don't recommend to use the heavy
RichTextBox
for your task. It will become slow when the output grows. Instead use a lightListBox
.ListBox
features UI virtualization and will significantly improve the performance. When you setListBoxItem.IsHitTestVisible
tofalse
, theListBox
will look and feel like a read-only document. Define a DataTemplate for each message type to control the appearance of the output:ILogMessage.cs
ErrorMessage.cs
A red message.
WarningMessage.cs
A yellow message.
InfoMessage.cs
A green message.
MainWindow.xaml.cs
MainWindow.xaml
See this example to know how to scroll the message view to the bottom when adding new items. You can use the example's
LogMessageBox
control (aUserControl
) and replace the aboveListBox
.