Matthew The Terrible
Matthew The Terrible

Reputation: 1643

MVVM: Using custom fonts with XAML in UWP

I'm trying to use icon font from weather-icons in an UWP application.

In my XAML I have something like

<Grid.Resources>
  <FontFamily x:Key="WeatherFonts">/Assets/Fonts/weathericons-regular-webfont.ttf#Weather Icons</FontFamily>
</Grid.Resources>
<TextBlock x:Name="tbFontAwesome" 
               Text="{Binding CurrentWeather.Icon}" 
               FontFamily="{StaticResource WeatherFonts}" 
               Foreground="White" 
               FontSize="72"/>

In my ViewModel I'm setting the

CurrentWeather.Icon = "&#xf00d;" 

If I just hardcode this in the XAML, it works fine.

<TextBlock x:Name="tbFontAwesome" 
               Text="&#xf00d;" 
               FontFamily="{StaticResource WeatherFonts}" 
               Foreground="White" 
               FontSize="72"/>

When I use the hardcoded XAML, the icon shows up just fine, but if I try doing the binding to the string, the TextBlock just shows the string and not the icon.

Upvotes: 3

Views: 193

Answers (1)

Justin XL
Justin XL

Reputation: 39006

Try System.Net.WebUtility.HtmlDecode("&#xf00d;").

Upvotes: 4

Related Questions