Does XAML TextBlock program special characters?

I want to use the awesome font ( http://fortawesome.imtqy.com/Font-Awesome/design.html ) in XAML.

I was able to easily get it to work through direct XAML by creating a font folder and adding a font there, and then in XAML:

<TextBlock FontFamily="Fonts/#FontAwesome">&#xf000;</TextBlock> 

Displays the martini icon.

However, when you add it programmatically, it simply displays the invalid character as follows: [] , I tried the following:

XAML:

 <TextBlock Name="textBlock"></TextBlock> 

WITH#

 textBlock.FontFamily = new FontFamily("Fonts/#FontAwesome"); textBlock.Text = HttpUtility.HtmlDecode("&#xf000;"); 

and the following, which returns a literal string:

 textBlock.FontFamily = new FontFamily("Fonts/#FontAwesome"); textBlock.Text = "&#xf000;"; 

Any ideas?

+6
source share
1 answer

try the following:

 textBlock.FontFamily= new FontFamily(new Uri("pack://application:,,,/"), @"/Fonts/#FontAwesome"); // you should well reference your font else you will get a square textBlock.Text = "\uf000";// \u (unicode escape char) instead of &#x 

and if you want to view your XAML text block, use

 t_out.Text = XamlWriter.Save(textBlock); 
+4
source

Source: https://habr.com/ru/post/944399/


All Articles