richtextblock converting string to paragraph class

1.1k Views Asked by At

I have a string filled as :

string link (Sorry but I couldn't add XAML formatted text in this text editor.)

I wanna convert this string to Paragraph class in run-time. So I can add it simply in RichTextBlock.

How can I convert this string to paragraph format? How can I do it

1

There are 1 best solutions below

0
On

Add some root element to the XAML so you can parse is as XML

var doc = XDocument.Parse("<root>"+yourStringVariable+"</root>");

the go over the paragraphs and process them

var paragraphs = new List<Paragraph>();
foreach (var p in doc.Descendants("Paragraph"))
{
    var paragraph = new Paragraph();
    paragraph.Inlines.Add(new Run {Text = p.Value});
}