wpf 有图片的按键样式

<Style x:Key="BtnBackgroundIconCustomDialogStyle" TargetType="{x:Type Button}">

<Setter Property="FocusVisualStyle" Value="{x:Null}" />

<Setter Property="SnapsToDevicePixels" Value="true" />

<Setter Property="Width" Value="150" />

<Setter Property="Height" Value="40" />

<Setter Property="BorderThickness" Value="0" />

<Setter Property="FontWeight" Value="Normal" />

<Setter Property="FontSize" Value="17" />

<Setter Property="Foreground" Value="White" />

<Setter Property="Background" Value="#049AFF" />

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type Button}">

<Border BorderThickness="{TemplateBinding BorderThickness}" Width="{TemplateBinding Width}" CornerRadius="4" Background="{TemplateBinding Background}" Effect="{TemplateBinding Effect}" HorizontalAlignment="Center">

<Grid HorizontalAlignment="Center">

<Grid.ColumnDefinitions>

<ColumnDefinition Width="Auto" />

<ColumnDefinition Width="*" />

</Grid.ColumnDefinitions>

<Image Grid.Column="0" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Tag}" Width="14" Height="14" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center" />

<TextBlock Grid.Column="1" Text="{TemplateBinding Content}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" FontWeight="{TemplateBinding FontWeight}" TextAlignment="Center" />

</Grid>

</Border>

<ControlTemplate.Triggers>

<Trigger Property="IsFocused" Value="True">

<Setter Property="Background" Value="#2B6FD5" />

<Setter Property="Foreground" Value="#fff" />

</Trigger>

<Trigger Property="IsMouseOver" Value="True">

<Setter Property="Background" Value="#2B6FD5" />

<Setter Property="Foreground" Value="#fff" />

</Trigger>

</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

相关推荐
万少14 小时前
HarmonyOS preview 预览文件 Kit 的入门讲解
前端
IT_陈寒14 小时前
JavaScript 性能优化实战:我从 V8 源码中学到的 7 个关键技巧
前端·人工智能·后端
jenchoi41314 小时前
软件供应链npm/pypi投毒预警情报【2025-11-09】
前端·安全·web安全·网络安全·npm·node.js
艾小码14 小时前
别再只会用默认插槽了!Vue插槽这些高级用法让你的组件更强大
前端·javascript·vue.js
JaguarJack14 小时前
CSS 也要支持 if 了 !!!CSS if() 函数来了!
前端·css
恋猫de小郭14 小时前
Flutter 3.38 发布,快来看看有什么更新吧
android·前端·flutter
beyond谚语18 小时前
第四章 依赖项属性
wpf
wuk99820 小时前
实现ROS系统的Websocket传输,向Web应用推送sensor_msgs::Image数据
前端·websocket·网络协议
合作小小程序员小小店1 天前
web网页开发,在线%考试管理%系统,基于Idea,vscode,html,css,vue,java,maven,springboot,mysql
java·前端·系统架构·vue·intellij-idea·springboot
天天进步20151 天前
CSS Grid与Flexbox:2025年响应式布局终极指南
前端·css