Showing html text in FlowDocumentReader

821 views Asked by At

I have a FlowDocumentReader control in my application.

<FlowDocumentReader Document="{Binding FlowDocument}" Style="{DynamicResource FlowDocumentStyle}" />

And here's how I set the text to the FlowDocumentReader:

Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add("some <b>book</b>");
FlowDocument.Blocks.Add(paragraph);

The problem is that 'book' isn't shown like html, the tags are visible in the wpf application.

I tried using this converter:

http://code.msdn.microsoft.com/windowsdesktop/XAML-to-HTML-Conversion-ed25a674/view/SourceCode

but then the text shown in my wpf application looks like this:

<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph>some <Run FontWeight="bold">book</Run></Paragraph></FlowDocument>

and again it's not bold. How can I do this?

1

There are 1 answers

4
ajay gandhi On

Use UI Elements to show formatted text and them to InlineUIContainer of Paragraph.

 Paragraph paragraph = new Paragraph();


        paragraph.Inlines.Add("some");
        Label lb = new Label();
        lb.FontWeight = FontWeights.Bold;
        lb.Content = " Book";
        paragraph.Inlines.Add(new InlineUIContainer(lb));
        this.Doc.Document = new FlowDocument();
        this.Doc.Document.Blocks.Add(paragraph);