如何在WPF中使用图标[Font-awesome] [英] how use icon [Font-awesome] in WPF

查看:129
本文介绍了如何在WPF中使用图标[Font-awesome]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WPF的新手.我想在文本框和按钮中使用真棒字体图标.但该图标未与我的文本框绑定

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 really need it please help me..

示例

第1步:下载真棒字体

工具->库软件包管理器->软件包管理器控制台 安装

Tools -> Library Package Manager -> Package Manager Console Install

PM>安装包FontAwesome.WPF

PM > Install-Package FontAwesome.WPF

第2步:添加资源

<Application> xmlns:fa="http://schemas.fontawesome.io/icons/" </Application>

第3步:放入App.xaml

Step 3 : Put App.xaml

<Application.Resources>

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

</Application.Resources>

第4步:在Demo.xaml中使用

Step 4 : Use it in Demo.xaml

<TextBlock Style="{StaticResource FontAwesome}"
FontSize="75"
Text="&#xf133;" />

第5步:-输出

推荐答案

首先,下载Font Awesome,提取ZIP文件,然后将fonts/fontawesome-webfont.ttf复制到解决方案的Fonts文件夹中.如果尚未将属性"中的构建操作"设置为资源"

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

接下来,在App.xaml中的资源中添加样式.不要忘记字体名称前面的#,并记住使用字体的内部名称,而不是文件名.要检查字体名称,只需双击字体文件,它将在Windows字体查看器中打开.字体名称将在顶部.

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>

打开MainWindow.xaml并使用以下代码段替换网格:

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="&#xf004;" 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>

注意"tbFontAwesome"文本块的"Text"属性,它是HeartUnicode.

Notice "Text" property of "tbFontAwesome" textblock, its the Unicode for Heart.

备忘单

这篇关于如何在WPF中使用图标[Font-awesome]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆