Dynamic bold and italic elements of WPF TextBlock

I am using the MVVM pattern and I have a row type property in my ModelView.

A string can contain the following HTML tags:

<b>, </b>, <i>, </i>  

I need certain parts of the text in a TextBlock to be normal, bold, or italic.

At the moment, I have created a workaround method, a helper method that works as follows:

  • Tear an HTML string apart

  • Creates an instance of the Run class

  • Depending on the tag, sets the FontWeight or FontStyle properties

  • Adds an instance of the Run class to the TextBlock Inlines collection.

This solution works, but it is not compatible with the MVVM pattern.

I was thinking about using Convertors, but I'm not sure which TextBlock property should be bound to.

What do you think, how to solve this problem?

+5
2

, .

BindableRichTextBox, http://www.shawnduggan.com/?p=54

  • HTML- XAML FlowDocument

  • BindableRichTextBox

  • RichTextBox TextBlock (Focusable = "False", BorderThinkness = "0", BorderBrush = "White".... ..)

+1

-, , ContentControl, Content ValueConverter, TextBlock. , .

+4

All Articles