我尝试从FontIcon类添加一些基本提供的图标,用于通用Windows 10应用程序(我们可以在appbar中看到的那些)。当运行这段代码时,它运行没有任何问题,但实际上,它显示了一些边框方块,例如无法识别的表情字符。
Button infoButton = new Button();
infoButton.Content = new FontIcon
{
FontFamily = new FontFamily("Segoe MDL2 Assets"),
Glyph = "",
Foreground = new SolidColorBrush(Colors.WhiteSmoke)
};
答案 0 :(得分:31)
这是XAML和C#如何处理Unicode字符的问题。在XAML代码中使用它时,它类似于Glyph = ""
,但是当您在C#代码中使用它时,它应该是这样的:Glyph = "\uE946"
。
此详细信息没有具体文档,但有些案例在MSDN& SO论坛具有相同的实现:AppBarButton.Icon doesn't change on runtime。
在C#代码后面,我们需要使用转义字符。
答案 1 :(得分:-1)
或者在XAML中:
<Button>
<Button.Content>
<FontIcon
FontFamily="Segoe MDL2 Assets"
Glyph=""/>
</Button.Content>
</Button>