在 wpf 中添加图标字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21374349/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:37:27  来源:igfitidea点击:

Add Icon font in wpf

wpffont-face

提问by Niloo

I want to add custom icon in WPF. I use entypoand Font-Awesome.

我想在 WPF 中添加自定义图标。我使用entypoFont-Awesome

I add this pakage in solution and use it in XAML.

我在解决方案中添加了这个包并在 XAML 中使用它。

<UserControl.Resources>
    <Style x:Key="FontAwesome">
        <Setter Property="TextElement.FontFamily" Value="fonts/FontAwesome.ttf" />
    </Style>
</UserControl.Resources>


<TextBlock Text="&#xf01a;" Style="{DynamicResource FontAwesome}" />

But don't show Icon.

但不要显示图标。

回答by K Mehta

Make sure your font is added as a resource. Then, use the following string:

确保您的字体作为资源添加。然后,使用以下字符串:

<Setter Property="TextElement.FontFamily" Value="pack://application:,,,/fonts/#FontAwesome" />

In the string above, I'm assuming that the font's name (notthe font's filename) is FontAwesome.

在上面的字符串中,我假设字体的名称(不是字体的文件名)是 FontAwesome。

回答by Sankarann

You can also use the Below structure if the font resource is in your solution folder,

如果字体资源在您的解决方案文件夹中,您也可以使用以下结构,

<Setter Property="TextElement.FontFamily" Value="../fonts/FontAwesome.ttf" />