0
votes

When I want to change my font icon background, they can't show well. However, when I just not change and they keep the original value I set in XAML, they are fine.

I think it may be the problem of my font, so I try other fonts, finally, I find that only icon font like "Segoe UI Emoji" "Segoe UI Symbol" and "Segoe UI Symbol" go wrong. Other fonts, like "Verdana" or "Arial", work well.

I use TextBlock Control and set it's FontFamily Property in XAML then change it's Text Property background in C#. I also try FontIcon Control, sadly, it can't work well either.

My UWP min and target version are both 10240, I write it in Visual Studio 2015.

Here is my code:

xaml

<TextBlock  Name="IconTextBlock"  Text="&#xE10B;" FontFamily="Segoe MDL2 Assets"/>

C#

private void ReFreshButton_Click(object sender, RoutedEventArgs e)
{ 
    IconTextBlock.Text = "&#xE106;";
}
1

1 Answers

1
votes

The problem appears to be how you're setting the character rather than the fonts.

XAML and C# use different formats to indicate Unicode characters by number. Your C# code snippet uses the XAML string literal format ("&#xE106;") instead of the C# string literal format ("\uE106"), and to C# the XML format is just text.

Instead of setting the string to Unicode character E106 (a cancel X mark) you're setting it to the actual string "&#xE106". This displays as boxes in "Segoe MDL2 Assets" since that font doesn't contain normal alphanumeric characters. If you look at the string in the debugger or display it with a normal-use font such as Verdana or Arial you should see the string spelled out as "&#xE106" rather than represented by the cancel glyph.

To get the same behavior from C# that you get from Xaml set the string literal per C#'s string syntax:

IconTextBlock.Text = "\uE106";