Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Special characters
3 replies. Latest Post by robertlair on October 13, 2008.
(0)
Galo
Member
39 points
72 Posts
10-10-2008 9:08 AM |
Hi Folks,
Just wondering if it's posible to display characters like ™ through ™ or something, is it posible ?
thanks!
pbrooks
Contributor
2671 points
355 Posts
10-11-2008 5:32 PM |
Galo,
You can use the following:
<TextBlock Text="Hello World ™"></TextBlock>
For a more complete list, please see the following resource:
http://www.w3.org/TR/REC-html40/sgml/entities.html
surbhiydv
Participant
1134 points
218 Posts
10-13-2008 5:35 AM |
A few more special characters:
Encoding
<
>
&
"
 
robertlair
79 points
43 Posts
10-13-2008 7:53 AM |
Also, to add to this. You can only use this syntax if you are putting the information in the XAML tag itself (also note, you cant use the special HTML characters, you must convert them all to Unicode... so your trademark would be ™.
If you need to assign the value in code, you will want to use the System.Windows.Browser.HttpUtility.HtmlDecode() method. So if you want to set the text property of the TextBlock x:Name="Title" to Microsoft Vista™ then you would want to use the following code:
1 Title.Text = System.Windows.Browser.HttpUtility.HtmlDecode("Windows Vista™");
Furthermore, if you want to to use it in data binding... You will need to use a value converter within the Binding extension property. So basically, your XMAL would look like this:
1 <TextBlock Text="{Binding Title, Converter={StaticResource htmlDecodeConverter}}" />
1 public class HtmlDecodeConverter : IValueConverter2 {3 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)4 {5 return System.Windows.Browser.HttpUtility.HtmlDecode(value as string);6 }7 8 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)9 {10 throw new NotImplementedException();11 }12 }
<UserControl.Resources> <local:HtmlDecodeConverter x:Key="htmlDecodeConverter" /></UserControl.Resources>
Thats about it! Hope this answers your question!