views:

442

answers:

3

I make calls to a webservice to get information that bind to the Text property of a TextBlock. Sometimes the information will contain encoded special characters for HTML - most notably the ® which I believe to the (r) symbol. The silverlight TextBlock just displays the raw text and not the (r). Of course, I can strip out the text, but it seems that someone on here will know how to translate HTMl codes like this into something that the TextBlock can understand. My first though is an iValueConverter with a Regex relace???

has anyone done one of these?

+1  A: 

I believe you should be using ® and not $#174;. I'm not sure about silverlight, but WPF will translate these literals automagically.

I admit that I don't think this will necessarily work if the text property is being databound. If that's the case, then an IValueConverter will be fine. Otherwise, you can also search/replace these literals in your object before the value is bound. This can be accomplished in your ViewModel (if you're following MVVM).

dustyburwell
+2  A: 

You just need to use HtmlDecode:

System.Windows.Browser.HttpUtility.HtmlDecode(yourStringHere)
Justin Niessner
Thanks. Just that easy. I was able to do this where I pull the data using XLINQ. I also think that this would be an easy iValueConvert
caryden
A: 

In HTML, entities like > refer to their decimal value in ASCII, so it is as simple as replacing the expression with its decimal value.

I've assumed that $#174; is a typo and you mean ®

David Caunt
I did mean that. Sorry. I have corrected above.
caryden