Add Icon font in wpf

2019-02-13 06:01发布

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

I add this pakage in solution and use it in 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.

标签: wpf font-face
2条回答
神经病院院长
2楼-- · 2019-02-13 06:40

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 (not the font's filename) is FontAwesome.

查看更多
该账号已被封号
3楼-- · 2019-02-13 06:42

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

<Setter Property="TextElement.FontFamily" Value="../fonts/FontAwesome.ttf" />
查看更多
登录 后发表回答