0

I used the following method (original source: https://itnext.io/convert-country-name-to-flag-emoji-in-c-the-net-ecosystem-115f714d3ef9) to generate the corresponding country flag from a CultureInfo.

public class Region
{
    public string Emoji { get;set;}
    public RegionInfo Info { get;set;}
    public CultureInfo Culture { get;set;}
}

public static class RegionsProvider
{
    public static Region GetRegion(CultureInfo culture)
    {
        var regionInfo = new RegionInfo(culture.LCID);

        var region = new Region
        {
            Culture = culture,
            Info = regionInfo,
            Emoji = IsoCountryCodeToFlagEmoji(regionInfo.TwoLetterISORegionName)
        };
        return region;
    }

    public static string IsoCountryCodeToFlagEmoji(string countryCode) => string.Concat(countryCode.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5)));
}
<TextBlock Text="{Binding Emoji}" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Info.EnglishName}"/>
<TextBlock Text=""/>

enter image description here

application started

enter image description here

Unfortunately, in my WinUI3 application this is not displayed, but only represented by the text "us".

Can it be because of the used character set?

Dominic Jonas
  • 4,329
  • 1
  • 29
  • 64
  • 3
    Behavior is expected, this has nothing to do with WinUI3. Windows doesn't support showing flags emoji: https://answers.microsoft.com/en-us/windows/forum/all/flag-emoji/85b163bc-786a-4918-9042-763ccf4b6c05 (the "Segoe UI Emoji" font doesn't have flags, except U+1F3F3 and U+1F3F4) – Simon Mourier Apr 11 '22 at 10:54

0 Answers0