wpf 如何在 XAML 中放置一个 unicode 字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1367202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put a unicode character in XAML?
提问by Alex Baranosky
I'm trying to do this:
我正在尝试这样做:
<TextBlock Text="{Binding Path=Text,
Converter={StaticResource stringFormatConverter},
ConverterParameter='&\u2014{0}'}" />
To get a — to appear in front of the text. It doesn't work. What should I be doing here?
得到一个 — 出现在文本前面。它不起作用。我应该在这里做什么?
回答by ferdley
Since XAML is an XML file format you could try the XML character escape. So instead of writing &\u2014
, you could write —
instead.
由于 XAML 是一种 XML 文件格式,您可以尝试使用 XML 字符转义。所以&\u2014
你可以写—
而不是写。
回答by sdd
In xaml I did it like this:
在 xaml 中,我是这样做的:
<Button Grid.Column="1" Grid.RowSpan="2" Name="start" Margin="5" Click="start_Click">
<TextBlock Name="test" FontFamily="pack://application:,,,/Y_Yoga;Component/Resources/#FontAwesome"></TextBlock>
</Button>
Hope to be helpful!
希望能有所帮助!
回答by Matas Vaitkevicius
Markup files that are created in Microsoft Visual Studio are automatically saved in the Unicode UTF-8 file format, which means that most special characters, such as accent marks, are encoded correctly. However, there is a set of commonly-used special characters that are handled differently. These special characters follow the World Wide Web Consortium (W3C) XML standard for encoding.
在 Microsoft Visual Studio 中创建的标记文件会自动以 Unicode UTF-8 文件格式保存,这意味着大多数特殊字符(例如重音符号)都已正确编码。但是,有一组常用的特殊字符的处理方式不同。这些特殊字符遵循万维网联盟 (W3C) XML 编码标准。
What this means is that you can do zalgo for all you care
这意味着你可以为所有你关心的事情做 zalgo
Bit of code that is relevant:
相关的代码位:
<Label Grid.Column="0" Grid.Row="3" FontWeight="ExtraBlack">STAGE:Mͣͭͣ̾ Vͣͥͭ͛ͤͮͥͨͥͧ̾</Label>
回答by Imran Shaik
I came to this page for some other reason, but this does not include the easiest and the obvious solution.
我出于其他原因来到此页面,但这不包括最简单和明显的解决方案。
This is what I do.
这就是我所做的。
Maintain a static class with all the Unicode values.
维护一个包含所有 Unicode 值的静态类。
public static class Icons
{
public const string IconName = "\u2014";
}
And then just bind it wherever you need it.
然后只需将其绑定到您需要的任何地方即可。
<TextBlock Text="{x:Static resources:Icons.IconName}" FontFamily="..."/>
This also helps you out with maintenance, all icons would be in one place to manage.
这也有助于您进行维护,所有图标都可以在一个地方进行管理。
回答by Akku
Save the file as UTF-8. In Visual Studio, you can do this by going "File" → "Advanced Save Options".
将文件另存为 UTF-8。在 Visual Studio 中,您可以通过转到“文件”→“高级保存选项”来执行此操作。