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>
相关推荐
yue00817 小时前
C# ASCII和字符串相互转换
c#
DICOM医学影像18 小时前
15. Go-Ethereum测试Solidity ERC20合约 - Go-Ethereum调用合约方法
开发语言·后端·golang·区块链·智能合约·以太坊·web3.0
quant_198618 小时前
如何处理大规模行情数据:从源头到终端的实战教程
大数据·开发语言·经验分享·python·金融
哆啦code梦18 小时前
Rust:高性能安全的现代编程语言
开发语言·rust
TypingLearn18 小时前
Perigon.CLI 10.0 重磅发布【AspNetCore开发模板和辅助工具】
c#·.net·aspnetcore
玄同76518 小时前
Python 装饰器:LLM API 的安全与可观测性增强
开发语言·人工智能·python·安全·自然语言处理·numpy·装饰器
superman超哥18 小时前
Rust 过程宏开发入门:编译期元编程的深度实践
开发语言·后端·rust·元编程·rust过程宏·编译期
GesLuck18 小时前
伺服电机(200 smart & )调试文档
开发语言·驱动开发·硬件工程
黎雁·泠崖18 小时前
Java底层探秘入门:从源码到字节码!方法调用的中间形态全解析
java·开发语言
千里马-horse18 小时前
TypedArrayOf
开发语言·javascript·c++·node.js·napi