[英]Create RTF run in flowdocument
Could anyone please help me understand RTF? 有人可以帮我理解RTF吗? I have an
inputStream
filled from some string 我有一些字符串填充的
inputStream
inputStream = new MemoryStream(Encoding.ASCII.GetBytes((myObject.someStr)));
Then this stream passed to flowdocument 然后将此流传递给flowdocument
FlowDocument fldoc = new FlowDocument();
TextRange tr = new TextRange(
fldoc.ContentStart, fldoc.ContentEnd);
tr.Load(inputStream, DataFormats.Rtf);
After that I create custom textbox to handle myObject
's property 之后,我创建自定义文本框来处理
myObject
的属性
Block curBlock = fldoc.Blocks.FirstBlock;
Inline curInline = (currentBlock as Paragraph).Inlines.FirstInline;
Run curRun = (currentInline as Span).Inlines.FirstInline as Run;
return new CustomTextBox(tr, currentRun.ContentStart, myObject)
Upon losing focus my custom text box does 失去焦点后,我的自定义文本框会
TextPointer ptr = CurrentRun.ContentStart;
ptr.DeleteTextInRun(ptr.GetTextRunLength(LogicalDirection.Forward));
ptr.InsertTextInRun(mainTextbox.Text);
using (MemoryStream ms = new MemoryStream())
{
tr.Save(ms, DataFormats.Rtf);
myObject.someStr = ASCIIEncoding.Default.GetString(ms.ToArray());
}
Now the problem: if myObject.someStr == ""
, then curBlock == null
, and I can not instantiate CustomTextBox. 现在的问题是:如果
myObject.someStr == ""
,那么curBlock == null
,并且我无法实例化CustomTextBox。 I am trying to 我在尝试着
Paragraph p = new Paragraph();
Span s = new Span();
Run r = new Run(tr.Text);
s.Inlines.Add(r);
p.Inlines.Add(s);
fldoc.Blocks.Add(new Paragraph());
return new CustomTextBox(tr, r.ContentStart, myObject)
, but tr is empty anyways. ,但tr还是空的。 How can I handle that?
我该如何处理?
fldoc = new FlowDocument(p);
帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.