WPF FontAwesome字体使用方法
作者:互联网
WPF FontAwesome字体使用方法
1、下载FontAwesome字体并解压放置在项目上如Fonts文件夹;
https://fontawesome.com/v5/cheatsheet
https://www.bootcss.com/p/font-awesome/design.html
http://www.fontawesome.com.cn/cheatsheet/
https://www.bootcss.com/p/font-awesome/
2、可以采用以下几种方法:
方法一:
APP.Xaml
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
<FontFamily x:Key="FontAwesome">/Fonts/fontawesome-webfont.ttf#FontAwesome</FontFamily>
</Application.Resources>
</Application>
方法二:
使用辅助类 FontUtils类,并在控件上引用该字体
// FontUtils类
public class FontUtils
{
static FontUtils()
{
try
{
Awesome = new FontFamily(new Uri(@"pack://application:,,,/FWindSoft.Wpf;component/Resources/"), "./#FontAwesome");
}
catch (Exception)
{
}
}
/// <summary>
/// Awesome字体
/// </summary>
public static FontFamily Awesome { get; private set; }
}
//窗体上引用字体类
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.FontFamily = FontUtils.Awesome;
this.tf.FontFamily = FontUtils.Awesome;
}
}
//MainWindow.Xaml 如 Content=""
<Button x:Name="tf" Content="" FontSize="18" HorizontalAlignment="Right" Margin="0,0,10,0" ></Button>
方法三:
3.1、nugut引用 搜索FontAwesome5
3.2、xmal窗体引入
xmlns:fa5=“http://schemas.fontawesome.com/icons/”
3.3、使用方法
<fa5:ImageAwesome Icon=“Solid_ExclamationTriangle” Foreground="#FFFF7400"/>
或
<fa5:FontAwesome Icon=“Solid_ExclamationTriangle” Foreground="#FFFF7400"/>
其他方法可见:https://stackoverflow.com/questions/38305239/how-use-icon-font-awesome-in-wpf
标签:Awesome,字体,FontAwesome,WPF,FontUtils,com,MainWindow 来源: https://blog.csdn.net/wpyok168/article/details/121988345