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>

相关推荐
拿破轮29 分钟前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端
whltaoin30 分钟前
【 Web认证 】Cookie、Session 与 JWT Token:Web 认证机制的原理、实现与对比
前端·web·jwt·cookie·session·认证机制
Aerelin1 小时前
爬虫playwright入门讲解
前端·javascript·html·playwright
5***o5001 小时前
前端在移动端中的NativeBase
前端
灵魂学者1 小时前
Vue3.x —— 父子通信
前端·javascript·vue.js·github
1***Q7841 小时前
前端跨域解决方案
前端
Macbethad1 小时前
使用WPF编写一个工控软件设置界面
wpf
小雨青年2 小时前
MateChat 进阶实战:打造零后端、隐私安全的“端侧记忆”智能体
前端·华为·ai·华为云·状态模式
勇气要爆发2 小时前
问:ES5和ES6的区别
前端·ecmascript·es6
永不停歇的蜗牛3 小时前
Maven的POM文件相关标签作用
服务器·前端·maven