I am new in WPF. I want to use Font-awesome Icon in textbox and button. but the icon is not bind with my textbox
I install Font-awesome resource to my application.<
I know this is an old question, and this option may not have been available to you at the time, so I thought I would provide an updated method for anyone who stumbles across this. I recommend you install the NuGet package 'FontAwesome5' from here:
FontAwesome5 on NuGet.org
or search "fontawesome5" in Visual Studio's built-in NuGet Package Manager window:
Tools > NuGet Package Manager > Manage NuGet Packages for Solution...
-it is usually the top result when using this exact search term.
Then simply add the following namespace to your XAML document:
xmlns:fa5="http://schemas.fontawesome.com/icons/"
and then you should find relative ease in adding icons to your project. For example:
<fa5:ImageAwesome Icon="Solid_ExclamationTriangle" Foreground="#FFFF7400"/>
or
<fa5:FontAwesome Icon="Solid_ExclamationTriangle" Foreground="#FFFF7400"/>
And the beauty of this is that IntelliSense will show you a list of all available icons, saving you the hassle of going to the website to search them up.
You could as well manually select FontAwesome from the FontFamily property of the TextBlock.That will solve the problem.
If FontAwesome is not among the list of fonts then you probably need to import the font file just like the first answer suggested.
To extend the accepted answer because it's somewhat out of date and missing information, here's what I did:
use-on-desktop
folder, locate the version you want. N.B. Solid has the most icons free; some icons require a Pro payment for Regular and Light versions.
Font Awesome 5 Free-Solid-900.otf
.Fonts
. Paste the fonts file inside this folder.FontAwesome.otf
for brevity<Application.Resources>
or other <ResourceDictionary>
, insert:<FontFamily x:Key="FontAwesome">/YOUR_PROJECT_NAME;component/Fonts/FontAwesome.otf#Font Awesome 5 Free Solid</FontFamily>
Fonts
, rename or omit this part of the path.First, download Font Awesome, extract the ZIP file and copy fonts/fontawesome-webfont.ttf
into a Fonts folder in your solution. Set the Build Action in the properties to Resource if it isn’t already
Next, add a Style to the Resources in App.xaml
. Don’t forget the #
at the front of the font name and remember to use the internal name of the font, not the name of the file. To check the name of the font, just double click on the font file and it will open in the Windows Font Viewer. The font name will be at the top.
<Application.resources>
<FontFamily x:Key="FontAwesome">/Fonts/fontawesome-webfont.ttf#FontAwesome</FontFamily>
</Application.resources>
Open MainWindow.xaml
and replace the grid with below snippet:
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="I" FontSize="32" Margin="10" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="tbFontAwesome" Text="" FontFamily="{StaticResource FontAwesome}" Foreground="Red" FontSize="32" Margin="10" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="Font Awesome" FontSize="32" Margin="10" VerticalAlignment="Center"></TextBlock>
</StackPanel>
</Grid>
Notice "Text"
property of "tbFontAwesome"
textblock, its the Unicode
for Heart
.
Cheat Sheet