8

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.

Niloo
  • 1,205
  • 5
  • 29
  • 53
  • `` is this works fine? is the font family is applied correctly? – Sankarann Jan 27 '14 at 07:01
  • Thanks, I use this but don't show icon and show a rectangle, I add Fonts folder(.eot,.svg,.ttf,.woff) to solution, Do i have any special settings? – Niloo Jan 27 '14 at 07:07

2 Answers2

12

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.

K Mehta
  • 10,323
  • 4
  • 46
  • 76
  • Thanks, I Go to property and choose action Embedded Resource for font file. and use this value, but don't show:( – Niloo Jan 27 '14 at 07:22
  • Thanks a lot, I remove font and add again, and use this value, it is ok :) – Niloo Jan 27 '14 at 07:38
  • Don't choose `Embedded Resource`, it is not supported in this case. Should select `Resource` instead, though `Content` is another possible choice. – terry Apr 16 '14 at 12:29
0

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

<Setter Property="TextElement.FontFamily" Value="../fonts/FontAwesome.ttf" />
Sankarann
  • 2,625
  • 4
  • 22
  • 59
  • Using relative paths is generally a bad idea - it relies on the location of your XAML files. – K Mehta Jan 27 '14 at 07:17
  • Yes ofcourse, i agree with that.. but i mean not to confuse him a lot.. Just it is an another way.. – Sankarann Jan 27 '14 at 07:21
  • What's your mean of 'font resource', I download fonts of http://fortawesome.github.io/Font-Awesome and and fonts folder to solution. – Niloo Jan 27 '14 at 07:24
  • It seems the problem with the Font file, I tried with the same font file downloaded from that location, no change in the font.. Better to check the font file with any word processing software and make use here.. – Sankarann Jan 27 '14 at 07:39