我想随用户输入更改RichTextBox的文本(粗体,下标等),所以这是我的代码:
private void FunctionRTB_TextChanged(object sender, TextChangedEventArgs e) {
if (IsEditing) return;
IsEditing = true;
FlowDocument flowDocument = new FlowDocument();
Paragraph paragraph = new Paragraph();
//
//populating 'paragraph'
//
flowDocument.Blocks.Add(paragraph);
//using (FunctionRTB.DeclareChangeBlock()) {
//FunctionRTB.BeginChange(); // tried this
FunctionRTB.Document = flowDocument;
//FunctionRTB.EndChange(); // with this, didnt work.
//}
IsEditing = false;
}
可是:
System.InvalidOperationException: 'Cannot set the Document property inside the scope of DeclareChangeBlock or BeginChange/EndChange calls.'
在:
FunctionRTB.Document = flowDocument;
我尝试使用DeclareChangeBlock()
和BeginChange()/EndChange()
。但是没有一个有效。
欢迎提出建议和链接。