开发者

adding RTF-tagged text to flowdocment in codebehind

开发者 https://www.devze.com 2023-02-07 22:15 出处:网络
I have rich text stored in a database with full RTF tagging, like so: {\\rtf1\\fbidis\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}}

I have rich text stored in a database with full RTF tagging, like so:

{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\ltrpar\cf1\f0\fs17 Email 开发者_运维问答sent on 10/1...

I want to make this text the source for a WPF FlowDocument. When I add this text to a paragraph directly, I see all of the tagging in the document.

   fd = New FlowDocument

   p = New Paragraph()
   p.FontSize = 12
   p.Foreground = Brushes.Black
   p.FontWeight = FontWeights.Normal
   p.Inlines.Add(New Run(vVariableWithRTFTagsInIt))
   fd.Blocks.Add(p)

How do I tell the FlowDocument that I'm adding tagged RTF? Thank you.


Apparently, lots of FlowDocument operations are done using TextRange class. Check out TextRange.Load Method:

TextRange range = new TextRange(fd.ContentStart, fd.ContentEnd);
range.Load(stream, DataFormats.Rtf);
0

精彩评论

暂无评论...
验证码 换一张
取 消