Wpf-自定义图标Button

FontFamily:指定图标字体资源文件;(推荐iconfont阿里矢量图标)

示例代码:

XML 复制代码
    <Style x:Key="MyIconButtonStyle" TargetType="Button">
        <Setter Property="Width" Value="40" />
        <Setter Property="Height" Value="30" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border Name="back" Background="Transparent">
                        <TextBlock HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   FontFamily="./Fonts/#iconfont"
                                   FontSize="{Binding FontSize, RelativeSource={RelativeSource AncestorType=Button, Mode=FindAncestor}}"
                                   Text="{Binding Content, RelativeSource={RelativeSource AncestorType=Button, Mode=FindAncestor}}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="back" Property="Background" Value="#FFFFFF" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="back" Property="Background" Value="#AAAAAA" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
相关推荐
闲人编程9 分钟前
Python游戏开发入门:Pygame实战
开发语言·python·游戏·pygame·毕设·codecapsule
是苏浙16 分钟前
零基础入门C语言之枚举和联合体
c语言·开发语言
报错小能手18 分钟前
C++笔记(面向对象)静态联编和动态联编
开发语言·c++·算法
小肖爱笑不爱笑27 分钟前
2025/11/5 IO流(字节流、字符流、字节缓冲流、字符缓冲流) 计算机存储规则(ASCII、GBK、Unicode)
java·开发语言·算法
瘦马31 分钟前
PhotoShop网页版(在线ps)在快速修复老照片,在线修旧如新
ui·photoshop·photoshop网页版·在线p图
手握风云-40 分钟前
Java 数据结构第二十八期:反射、枚举以及 lambda 表达式
java·开发语言
ᐇ95944 分钟前
Java Vector集合全面解析:线程安全的动态数组
java·开发语言
我是唐青枫1 小时前
C#.NET Random 深入解析:随机数生成原理与最佳实践
c#·.net
光头闪亮亮1 小时前
电子发票解析工具-c#桌面应用开发案例详解
c#
Hello_WOAIAI1 小时前
2.4 python装饰器在 Web 框架和测试中的实战应用
开发语言·前端·python