Tim Bee
Tim Bee

Reputation: 2230

Emojis in XAML & C# on WP8.1 with longer Unicode range

I am seeing a very weird behavior in my WP8.1 APP. In my XAML I have the following, which perfectly translates into a nice 😠 (ANGRY FACE), all is right.

<TextBlock x:Name="FaceTextBlock" Text="&#x1F620;" FontFamily="Segoe UI Symbol" />

But when I try to do it programmatically, it behaves as if the last digit - '0' - was not there:

FaceTextBlock.Text = "\u1F620"; // This behaves like "\u1F62" and is displayed  as "ὢ0"

As a counter example, I tried using the simple "Plane Emoji" ✈ "U+2708" which works fine. Any idea what I am missing here? Could it be due to the culture?

FaceTextBlock.Text = "\u2708"; // This works fine

Upvotes: 1

Views: 943

Answers (1)

Martin Liversage
Martin Liversage

Reputation: 106816

A Unicode character escape in C# is represented using either 4 or 8 hex digits so you have to write the emoji using 8 digits:

"\U0001F620"

Note the capital U as documented in 2.4.1 Unicode character escape sequences.

Upvotes: 2

Related Questions