最常用的图片按钮:
  有正常背景、鼠标滑过背景、鼠标按下背景、不可用背景、鼠标滑过透明度、是否是透明模式(若是则仅需正常背景即可,鼠标滑过和按下时则仅改变透明度),样式放在Generic.xaml中。
  
  示例:

 public class ImageButton : Button{static ImageButton(){DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));}public static readonly DependencyProperty MouseOverBackgroundProperty = DependencyProperty.Register("MouseOverBackground", typeof(Brush), typeof(ImageButton), new FrameworkPropertyMetadata(null));public Brush MouseOverBackground{get{return (Brush)this.GetValue(ImageButton.MouseOverBackgroundProperty);}set{this.SetValue(ImageButton.MouseOverBackgroundProperty, value);}}public static readonly DependencyProperty MousePressedBackgroundProperty = DependencyProperty.Register("MousePressedBackground", typeof(Brush), typeof(ImageButton), new FrameworkPropertyMetadata(null));public Brush MousePressedBackground{get{return (Brush)this.GetValue(ImageButton.MousePressedBackgroundProperty);}set{this.SetValue(ImageButton.MousePressedBackgroundProperty, value);}}public static readonly DependencyProperty UnEnabledBackgroundProperty = DependencyProperty.Register("UnEnabledBackground", typeof(Brush), typeof(ImageButton), new FrameworkPropertyMetadata(null));public Brush UnEnabledBackground{get{return (Brush)this.GetValue(ImageButton.UnEnabledBackgroundProperty);}set{this.SetValue(ImageButton.UnEnabledBackgroundProperty, value);}}public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(ImageButton), new FrameworkPropertyMetadata(null));public CornerRadius CornerRadius{get{return (CornerRadius)this.GetValue(ImageButton.CornerRadiusProperty);}set{this.SetValue(ImageButton.CornerRadiusProperty, value);}}public Brush MouseOverForeground{get { return (Brush)GetValue(MouseOverForegroundProperty); }set { SetValue(MouseOverForegroundProperty, value); }}// Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...public static readonly DependencyProperty MouseOverForegroundProperty =DependencyProperty.Register("MouseOverForeground", typeof(Brush), typeof(ImageButton));public bool IsOpacityMode{get { return (bool)GetValue(IsOpacityModeProperty); }set { SetValue(IsOpacityModeProperty, value); }}// Using a DependencyProperty as the backing store for IsOpacityMode.  This enables animation, styling, binding, etc...public static readonly DependencyProperty IsOpacityModeProperty =DependencyProperty.Register("IsOpacityMode", typeof(bool), typeof(ImageButton), new PropertyMetadata(false));public double MouseOverOpacity{get { return (double)GetValue(MouseOverOpacityProperty); }set { SetValue(MouseOverOpacityProperty, value); }}// Using a DependencyProperty as the backing store for MouseOverOpacity.  This enables animation, styling, binding, etc...public static readonly DependencyProperty MouseOverOpacityProperty =DependencyProperty.Register("MouseOverOpacity", typeof(double), typeof(ImageButton), new PropertyMetadata(0.8));}

style:

  <Style TargetType="{x:Type local:ImageButton}"><Setter Property="Background" Value="White"/><Setter Property="Cursor" Value="Hand"/><Setter Property="FocusVisualStyle" Value="{x:Null}"/><Setter Property="CornerRadius" Value="5"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="local:ImageButton" ><Border x:Name="border" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding CornerRadius}"BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"><ContentPresenter Focusable="False" RecognizesAccessKey="True" VerticalAlignment="Center" HorizontalAlignment="Center"/></Border><ControlTemplate.Triggers><!--透明度模式--><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsOpacityMode" Value="True"/><Condition Property="IsMouseOver" Value="True"/></MultiTrigger.Conditions><Setter Property="Opacity" Value="{Binding MouseOverOpacity,RelativeSource={RelativeSource Mode=Self}}"/></MultiTrigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsOpacityMode" Value="True"/><Condition Property="IsPressed" Value="True"/></MultiTrigger.Conditions><Setter Property="Opacity" Value="{Binding MouseOverOpacity,RelativeSource={RelativeSource Mode=Self}}"/></MultiTrigger><!--背景图片模式--><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsOpacityMode" Value="False"/><Condition Property="IsMouseOver" Value="True"/></MultiTrigger.Conditions><Setter  Property="Background" TargetName="border"Value="{Binding MouseOverBackground,RelativeSource={RelativeSource TemplatedParent}}"/><Setter Property="Foreground" Value="{Binding MouseOverForeground,RelativeSource={RelativeSource Mode=Self}}"/></MultiTrigger><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsOpacityMode" Value="False"/><Condition Property="IsPressed" Value="True"/></MultiTrigger.Conditions><Setter  Property="Background" TargetName="border"Value="{Binding MousePressedBackground,RelativeSource={RelativeSource TemplatedParent}}"/><Setter Property="Foreground" Value="{Binding MouseOverForeground,RelativeSource={RelativeSource Mode=Self}}"/></MultiTrigger><Trigger Property="IsEnabled" Value="False"><Setter  Property="Background" TargetName="border"Value="{Binding UnEnabledBackground,RelativeSource={RelativeSource TemplatedParent}}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

Generic.xaml:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:Senlan.CloudPos.Toolkit"><ResourceDictionary.MergedDictionaries><ResourceDictionary  Source="/此处为项目名;component/ImageButton/ImageButtonStyle.xaml"/><ResourceDictionary  Source="/此处为项目名;component/WaterTextBox/WaterTextBoxStyle.xaml"/><ResourceDictionary  Source="/此处为项目名;component/ImageRadioButton/ImageRadioButtonStyle.xaml"/><ResourceDictionary  Source="/此处为项目名;component/ImageCheckBox/ImageCheckBoxStyle.xaml"/></ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

WPF ImageButton相关推荐

  1. 分享Silverlight 3D开源项目和Silverlight/WPF/Windows Phone一周学习导读(4月25日-4月29日)...

    Silverlight 5 Beta版本中最引人注目的特性是3D功能,Silverlight 5与XNA Framework的结合,使Silverlight完美支持3D效果. 在微软MIX11大会后, ...

  2. 分享Silverlight 3D 房屋设计 和 游戏 开源项目

    2011-05-03 06:53 by jv9, 2849 阅读, 6 评论, 收藏, 编辑 Silverlight 5 Beta版本中最引人注目的特性是3D功能,Silverlight 5与XNA ...

  3. 潜移默化学会WPF(绚丽篇)--热烈欢迎RadioButton,改造成功,改造成ImageButton,新版导航 - AYUI框架 - 博客园...

    潜移默化学会WPF(绚丽篇)--热烈欢迎RadioButton,改造成功,改造成ImageButton,新版导航 - AYUI框架 - 博客园 原文:潜移默化学会WPF(绚丽篇)--热烈欢迎Radio ...

  4. 分享Silverlight/WPF/Windows Phone一周学习导读(10月1日-10月15日)

    分享Silverlight/WPF/Windows Phone一周学习导读(10月1日-10月15日) 本周Silverlight学习资源更新: [Silverlight入门系列]ListboxIte ...

  5. WPF 使用依赖属性(DependencyProperty) 定义用户控件中的Image Source属性

    原文:WPF 使用依赖属性(DependencyProperty) 定义用户控件中的Image Source属性 如果你要自定义一个图片按钮控件,那么如何在主窗体绑定这个控件上图片的Source呢? ...

  6. [Wpf] . [Theme] 重构/Themes/Generic.xaml 创建一个Custom Control的典型做法

    转载自:https://www.codeproject.com/Articles/433476/Structuring-Your-XAML-Sources -------------- Structu ...

  7. 分享Silverlight/WPF/Windows Phone/HTML5一周学习导读(12月26日-1月1日)

    分享Silverlight/WPF/Windows Phone/HTML5一周学习导读(12月26日-1月1日) 本周Silverlight学习资源更新   vs2010 学习Silverlight学 ...

  8. 分享Silverlight/WPF/Windows Phone一周学习导读(8月28日-9月3日)

    分享Silverlight/WPF/Windows Phone一周学习导读(8月28日-9月3日) 本周Silverlight学习资源更新: Silverlight动画 cutylongshen Si ...

  9. (WPF)酷狗音乐播放器

    最近看了下wpf,感觉wpf做界面实在是太方便,使用blend来设计界面简直不要太爽.通过mvvm模式来实现逻辑界面分离.我这里使用的是vs2013, .netFramework4.5.程序只是实现了 ...

  10. WPF控件库:图片按钮的封装

    需求:很多时候界面上的按钮都需要被贴上图片,一般来说: 1.按钮处于正常状态,按钮具有背景图A 2.鼠标移至按钮上方状态,按钮具有背景图B 3.鼠标点击按钮状态,按钮具有背景图C 4.按钮处于不可用状 ...

最新文章

  1. openssl的实践应用
  2. 微信更新的这功能“炸了”:网友集体吐槽 忍不了
  3. python语音属于什么语言_python到底是什么类型的语言
  4. 100个常用的Linux命令
  5. 赛尔笔记 | 自然语言处理中的迁移学习(下)
  6. 如何安装.nupkg文件
  7. 平面设计个人简历模板
  8. 离散LQR与iLQR的推导思路
  9. PHP公文签报源码,基于PHP企业公文流转系统.docx
  10. 破而后立,破除陈旧,认识自我,而后顶天立地!
  11. Android自定义一个时间轴,通过ListView来实现时间轴的效果
  12. rockchip eDP 配置
  13. python bunch制作可导入数据_python – ImportError:无法导入名称Bunch scikit-learn 0.19
  14. matlab编写多目标测试函数SCH, ZDT, MOP, DTLZ
  15. centos7利用docker 快速搭建苹果CMS站点
  16. 西门子医疗与全景医学共推基层医疗远程影像诊断全面应用;汤臣倍健捐赠670万元营养品与合作伙伴共同支援西安、珠海抗疫 | 医药健闻...
  17. oracle为什么打开鼠标不见了,鼠标箭头突然不见了该怎么办呢?
  18. Server 2016 + Win10 搭建CA证书登录环境
  19. 【Allegro_SPB_16.6安装详细教程】手把手搭建到Win10
  20. 【每日一题】宝石与石头

热门文章

  1. 通过银行卡号获取银行名称和银行图标的ICON
  2. 根据银行卡号 获取银行名称及银行logo
  3. 海康威视Android SDK,并非萤石Android SDK
  4. 怎么修改服务器ipmi地址,设置linux服务器ipmi地址
  5. 无需手机NFC 如何使用微信小程序制作amiibo卡
  6. Hbase API学习
  7. easyUi后台,模板实现前台简易版网上书店功能实现
  8. 遗传算法优化模糊控制规则
  9. SQL server 2008 如何卸载干净
  10. 政企数字化转型怎么做?先从华为云WeLink “云签约”打个样儿