I'm using MVVM pattern and I have string type property in my ModelView.
The string may contain following HTML tags:
<b>, </b>, <i>, </i>
I need to make certain parts of text in TextBlock to be in normal, bold or italic.
At moment I have created workaround, a helper method that works like this:
Breaks HTML string into parts
Creates instance of Run class
Depending on tag, sets FontWeight or FontStyle properties
Adds instance of Run class to TextBlock's Inlines collection
This solution works, but it is not compatible with MVVM pattern.
I was thinking of using Convertors, but I'm not sure what property of TextBlock should I do binding to.
What do You think, how can this problem be solved?
Something I've done in the past is to use a ContentControl, with the Content property bound to the string with a ValueConverter that returns a dynamically created TextBlock. Other solutions can be found here, including this one.
The easiest solution that I've found for this problem.
Is to use BindableRichTextBox, that can be found at http://www.shawnduggan.com/?p=54
Using Convertors convert HTML string to XAML and then make it into FlowDocument object
Bind Document to BindableRichTextBox
Make RichTextBox look like TextBlock (Focusable="False", BorderThinkness="0", BorderBrush="White"....etc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With