Emoji is represented by a single Unicode character or a specific sequence of Unicode characters.
For example , π€ is represented by U+1F914
.
The full list of emojis can be found here.
Since XAML is an XML-based markup language, we have to use XML escape character &#;
and we have to replace U+
prefix by x
for each part of our emoji :
U+1F914
become 🤔
:
<Label Text="🤔" />
if you want to use Data Binding to display emoji, letβs define a class that will represent emoji:
using System;
using System.Text;
namespace EmojiInXaml.Models
{
/// <summary>
/// Emoji class.
/// </summary>
public class Emoji
{
readonly int[] codes;
public Emoji(int[] codes)
{
this.codes = codes;
}
public Emoji(int code)
{
codes = new int[] { code };
}
public override string ToString()
{
if (codes == null)
return string.Empty;
var sb = new StringBuilder(codes.Length);
foreach (var code in codes)
sb.Append(Char.ConvertFromUtf32(code));
return sb.ToString();
}
}
}
It requires a single Unicode character or sequence of characters as an input and simply overrides the ToString
. Please note that U+
prefix should be replaced with 0x
to specify hexadecimal notation.
Example of usage
// person biking => http://www.unicode.org/emoji/charts/full-emoji-list.html#1f6b4
string bikingEmoji = new Emoji(0x1F6B4).ToString(); // π΄
<Label Text="{Binding bikingEmoji}" />