1.打开iconfont添加自己想要的图标到购物车
2.下载代码到本地
3.wpf项目里新建文件夹Fonts,并把iconfont.ttf拷贝进来
4.这一步很关键,将文件生成为资源,要不然在xaml里面看的是正常的,但是运行的时候会变成口
5.修改App.xaml代码
<Application x:Class="_3Dprinter_yz.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:_3Dprinter_yz"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Panuon.WPF.UI;component/Control.xaml" />
</ResourceDictionary.MergedDictionaries>
<FontFamily x:Key="IconFont">
Pack://application:,,,/Fonts/#iconfont
</FontFamily>
</ResourceDictionary>
</Application.Resources>
</Application>
6.修改按钮代码
<Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="30" IsDefault="True" Height="30"
FontSize="10" Foreground="White" Background="#363636" pu:ButtonHelper.CornerRadius="4" Click="Button_Click_2">
<TextBlock Text="󰆣" FontFamily="{StaticResource IconFont}" FontSize="20px" />
</Button>
或者App.xaml不修改,直接写成下面那种文章来源:https://www.toymoban.com/news/detail-516809.html
<Button HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="30" IsDefault="True" Height="30"
FontSize="10" Foreground="White" Background="#363636" pu:ButtonHelper.CornerRadius="4" Click="Button_Click_2">
<TextBlock Text="󰆣" FontFamily="pack://application:,,,/Fonts/#IconFont" FontSize="20px" />
</Button>
文章来源地址https://www.toymoban.com/news/detail-516809.html
到了这里,关于wpf 按钮添加图标的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!