2017-03-07 22 views
3

我试图在UWP应用程序中使用weather-icons的图标字体。MVVM:在UWP中使用自定义字体和XAML

在我的XAML我有类似

<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"/> 

在我视图模型我设置

CurrentWeather.Icon = "&#xf00d;" 

如果我只是硬编码这在XAML,它工作正常。

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

当我使用硬编码的XAML,图标显示出来就好了,但如果我尝试做绑定到字符串时,TextBlock只是显示了字符串,而不是图标。

回答

4

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

+0

这工作。我遇到了麻烦,但事实证明还有另一个问题。感谢帮助的人。 –

+0

@MatthewTheTerrible nws。很高兴听到你解决它! –