Erre Efe
Erre Efe

Reputation: 15557

Character encoding for use within ItemTemplate

I'm creating a menu from a ListBox. I'm using FontAwesome to create some font-icons. This is part of the ListBox ItemTemplate.

<TextBlock FontFamily="FontAwesome" VerticalAlignment="Center" HorizontalAlignment="Center" 
                               FontSize="32" Text="{Binding MenuCode}"
                               ToolTip="{Binding Tooltip}" >

The problem resides within the TextBlock's Text. I need to display the symbol, not the menu code. So, for example, if I use Text="&#xf001;" directly, then the music icon appears (fixed for all the items), but when I use DataBinding (each item has a different symbol): Text="{Binding MenuCode}" then the text &#xf001; (that is, the menu code as string) appears (as text, no icon). I guess problem is related with encoding, but can't fix it. Any idea?

Upvotes: 0

Views: 97

Answers (1)

Matthew Barthel
Matthew Barthel

Reputation: 26

Wrong escape sequence. HTML uses '#&x' while C# uses \u. So your "#&xF001" would become "\uF001"

Upvotes: 1

Related Questions