简体   繁体   English

在代码隐藏中使用时,Unicode字符(U + 1FXYZ)无法正确输出

[英]Unicode character (U+1FXYZ) not outputting correctly when used in code-behind

In my code-behind, I'm trying to return the hexcode for a unicode character. 在我的代码隐藏中,我正在尝试返回unicode字符的十六进制代码。

I'm trying to output any one of these characters for the Segoe UI Symbol font: http://www.istartedsomething.com/uploads/emojisegoe.html . 我正在尝试输出Segoe UI Symbol字体中的任何一个字符: http//www.istartedsomething.com/uploads/emojisegoe.html For example, "U+1F60A". 例如,“U + 1F60A”。

If I do so via my xaml, such as: 如果我通过我的xaml这样做,例如:

FontFamily="Segoe UI Symbol" Text="😊"

Then it works fine. 然后它工作正常。

But if I bind the value to retrieve it via a .cs converter class, the correct character doesn't appear: 但是如果我绑定值以通过.cs转换器类检索它,则不会出现正确的字符:

FontFamily="Segoe UI Symbol" Text="{Binding Pivot7Days.EmojiWeekendSummary, Converter={StaticResource EmoticonConverter}}"

Converter class: 转换器类:

switch (input)
{
    case "happy":
        return "\u1F60A";
    case "sad":
        return "\u1F60B";
    default:
        return "\u1F610";
}

I get an entirely different character followed by the final character in the returned string, such as 'A', 'B' or '0'. 我得到一个完全不同的字符,后跟返回字符串中的最后一个字符,例如'A','B'或'0'。 For example, when I should be seeing a face with tongue out (U+1F60B), I instead get the following: 例如,当我看到一张带舌头的脸(U + 1F60B)时,我会得到以下内容:

在此输入图像描述

Am I using the incorrect escape sequence in my code behind? 我在后面的代码中使用了不正确的转义序列吗?

超出U + FFFF的字符不能直接写成\\u....文字(如果你试过,只使用前四个十六进制数字,你得到一个错误的字符)但是作为代理对,或者更容易,使用8位\\U字面,例如U + 1F60A的'\\U0001F60A'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在代码隐藏中将Unicode字符设置为Label的内容? - How to set Unicode character as Content of Label in the code-behind? 如何在后台代码中将Unicode字符设置为TextBlock的Text? - How to set Unicode character as Text of TextBlock in the code-behind? 无法正确实现 README 文件中的代码隐藏 - Can't implement the code-behind from the README file correctly 正确设置 razor 页面以访问代码隐藏中的数据 - Setup correctly a razor page to have access to data in code-behind ASP.NET-当标记使用本地化的代码时,为什么在代码隐藏中使用默认的resx文件? - ASP.NET - why is the default resx file being used in the code-behind when the localized one is being used by the markup? 尝试从MainWindow后台代码绑定到UserControl后台代码时,数据绑定失败 - Data binding failing when trying to bind from MainWindow code-behind to UserControl code-behind MVC中的代码隐藏 - Code-behind in MVC 单击按钮时用于运行代码隐藏代码的Javascript - Javascript for running code-behind code when a button is clicked 与标记后代码相比,在标记中声明数据源的区别? - Difference when declaring a DataSource in markup compared to code-behind? 关闭浏览器时调用代码隐藏方法 - Invoke code-behind method when browser is closing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM