我有一个看起来如下的标签:
<Label Name="FalsePositiveInput" Content="✓">
这有效,但我怎么能在代码隐藏中做到这一点?我试过这个,但显然它不起作用:
FalsePositiveInput.Content = "✓";
我要显示的字符是复选标记符号
答案 0 :(得分:29)
使用unicode转义序列,而不是字符实体:
FalsePositiveInput.Content = "\u2713";
答案 1 :(得分:10)
+1为一二三
只需一句话:如果您想使用扩展Unicode,则不需要使用\u
,而是使用\U
和8个字符,例如显示您需要使用的左指放大镜(1F50D http://www.fileformat.info/info/unicode/char/1f50d/index.htm):
this.MyLabel.Text = "\U0001F50D";
或者根据建议您可以直接粘贴到源代码中,然后您不需要像"//it is a magnifying glass"
这样的注释,但是您必须将源代码保存为Unicode,这可能不是什么你想要的。
答案 2 :(得分:4)
返回检查符号 这适用于代码隐藏和报告:)
public static string FormatValue(object value, string format)
{
if (value == null) return "";
Type type = value.GetType();
if (type == typeof(bool))
{
if (string.IsNullOrEmpty(format))
{
if ((bool)value)
{
return "Yes";
}
else
{
return "No";
}
}
else
{
if ((bool)value)
{
return ((char)0x221A).ToString();
}
else
{
return "";
}
}
}
return value.ToString();
}
答案 3 :(得分:2)
如果字符是常量并且在编译时知道,我很确定你可以简单地在源代码文件中编写字符,而不将其编码为HTML实体。换句话说,源文件可以是Unicode编码的,Visual Studio会处理它(或者至少它对我来说)。
答案 4 :(得分:0)
+1 Dario,
如果它是复选标记符号,则只需将其从其他来源复制到您的代码中即可。
例如在维基百科上轻松找到。
他们是: ✓,✔,☑
答案 5 :(得分:0)
从这里复制和过去的caractor
那么你在xamal中的文字就像这样
<Button Text="← Bla bla" >