【发布时间】:2018-04-12 22:54:59
【问题描述】:
我的 GUI 上有一个 RichTextBox,我有两个按钮,一个用于显示数据,一个用于清除数据。在按钮 DISPLAY 上,我使用此例程将一些数据显示到 RichTextBox 中:
Block firstBlock = richTextBox_Console.Document.Blocks.FirstOrDefault();
richTextBox_Console.Document.Blocks.InsertBefore(firstBlock, new Paragraph(new Run("MyFirstLine= " + MyVariable + "\n" )));
string message;
for (int i = 0; i < 6; i++)
{
message = "";
message += "Line:" + (i + 1).ToString() + "\n";
richTextBox_Console.Document.Blocks.InsertBefore(firstBlock, new Paragraph(new Run(message)));
}
点击清除,我会this:
richTextBox_Console.SelectAll();
richTextBox_Console.Selection.Text = "";
现在当我再次点击“显示”按钮时,在线:
richTextBox_Console.Document.Blocks.InsertBefore(firstBlock, new Paragraph(new Run("MyFirstLine= " + MyVariable + "\n" )));
firstBlock 是null 所以该行会抛出这个错误:
值不能为空。参数名称:nextSibling
知道发生了什么吗?第一次显示数据可以正常工作,然后永远不会工作。
我也尝试使用richTextBox_Console.Document.Blocks.Clear(); 来清除,但我仍然遇到同样的错误。
【问题讨论】:
标签: c# wpf richtextbox