WPF 自定义图片按钮
此文档仅仅是一个BaseCode,已做后续查阅
XAML代码:
<Button x:Class="IM.UI.UC.IM_ImageButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Name="loc">
<Image Name="innerImage" Stretch="None" Source="{Binding Path=ImageSourceEx,ElementName=loc}" />
</Button>
CS代码:
public IM_ImageButton()
{
InitializeComponent();
FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(IM_ImageButton), new FrameworkPropertyMetadata(typeof(Button)));
this.IsEnabledChanged += new DependencyPropertyChangedEventHandler(ImageButton_IsEnabledChanged);
}
public ImageSource GrayImageSourceEx
{
get { return (ImageSource)GetValue(GrayImageSourceExProperty); }
set { SetValue(GrayImageSourceExProperty, value); }
}
public static readonly DependencyProperty GrayImageSourceExProperty =
DependencyProperty.Register("GrayImageSourceEx", typeof(ImageSource), typeof(IM_ImageButton), new UIPropertyMetadata(null));
public ImageSource ImageSourceEx
{
get { return (ImageSource)GetValue(ImageSourceExProperty); }
set { SetValue(ImageSourceExProperty, value); }
}
public static readonly DependencyProperty ImageSourceExProperty =
DependencyProperty.Register("ImageSourceEx", typeof(ImageSource), typeof(IM_ImageButton), new UIPropertyMetadata(null)); //当前按钮显示状态被禁用或启用
protected void ImageButton_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (this.IsEnabled && (this.ImageSourceEx != null))
{
this.innerImage.Source = this.ImageSourceEx;
}
else if (!(this.IsEnabled || (this.GrayImageSourceEx == null)))
{
this.innerImage.Source = this.GrayImageSourceEx;
} }
WPF 自定义图片按钮的更多相关文章
- WPF 自定义图片剪切器 - 头像剪切(扩展与完善、实时截图)
原文:WPF 自定义图片剪切器 - 头像剪切(扩展与完善.实时截图) 一.说明:上一次写的"WPF 自定义图片剪切器 - 头像剪切.你懂得"存在明显的缺陷,由于篇幅较长.重新写了一 ...
- Mono自定义图片按钮
首先,我们编写一个MyImageButton类,继承自LinearLayout public class MyPhoneImageButton:LinearLayout { private Image ...
- 【WPF】图片按钮的单击与双击事件
需求:ListBox中的Item是按钮图片,要求单击和双击时触发不同的事件. XAML中需要引入System.Windows.Interactivity.dll xmlns:i="clr-n ...
- wpf 自定义Button按钮
创建ButtonEx类 public class ButtonEx : Button { static ButtonEx() { DefaultStyleKeyProperty.OverrideMet ...
- 自己写一个图片按钮(XAML)
有时需要用三张图片(正常状态,鼠标移上,鼠标按下)来作为一个按钮的样式,虽然这种做法不好,应该用矢量的方式制作样式,但有的时候还是需要这样做的. 每次都修改按钮的样式来实现这个做法,既麻烦又会生成大段 ...
- WPF控件库:图片按钮的封装
需求:很多时候界面上的按钮都需要被贴上图片,一般来说: 1.按钮处于正常状态,按钮具有背景图A 2.鼠标移至按钮上方状态,按钮具有背景图B 3.鼠标点击按钮状态,按钮具有背景图C 4.按钮处于不可用状 ...
- tableView左划自定义带图片按钮
本方法实现的原理是将自定义按钮加在tableViewCell.contentView的屏幕外的frame上,打个比方,如果是5系的话,那么你自定义按钮的frame的起点就在(320+,0)(320+表 ...
- WPF利用Image实现图片按钮
之前有一篇文章也是采用了Image实现的图片按钮,不过时间太久远了,忘记了地址.好吧,这里我进行了进一步的改进,原来的文章中需要设置4张图片,分别为可用时,鼠标悬浮时,按钮按下时,按钮不可用时的图片, ...
- 【WPF】Button按钮添加背景图片
只是想做一个很简单的图片按钮而已,不需要那么复杂. <Button x:Name="btn" Width="145" Height="30&qu ...
随机推荐
- Bzoj3473
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3473 题解:待更 代码:待更 开始时间: 结束时间:
- iOS 之 网络 NSURLSession
NSURLSession相比NSURLConnection功能更强大,是更上层的网络封装.相比而言,普通应用场景下NSURLSession没有什么优势,但是,在程序切换到后台的情况下,NSURLSes ...
- CART分类与回归树 学习笔记
CART:Classification and regression tree,分类与回归树.(是二叉树) CART是决策树的一种,主要由特征选择,树的生成和剪枝三部分组成.它主要用来处理分类和回归问 ...
- ubuntu系统中crontab的使用介绍
1.创建crontab任务 用户hancool
- PHP之Mysql常用SQL语句示例的深入分析
1.插入数据insert into表名(列名1,列名2,列名..) values(值1,值2,值...); insert into product(name, price, pic_path) val ...
- 对js原型对象的拓展和原型对象的重指向的区别的研究
我写了如下两段代码: function Person(){} var p1 = new Person(); Person.prototype = { constructor: Person, name ...
- 在iOS微信浏览器中自动播放HTML5 audio(音乐)的2种正确方式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Bloom Filter的基本原理和变种
学习一个东西首先要知道这个东西是什么,可以做什么,接着再了解这个东西有什么好处和优势,然后再学习他的工作原理.下面我们分别从这三点简单介绍一下bloom filter,以及和他的变种. What:在允 ...
- loadrunner controller:设置多个load generator
下面讲一下如何使用多台电脑进行负载测试. 1) 打开load generator,如图所示默认已添加了我们本地的Generator: 2) 点击"Add. ...
- 转:C# Process.Start()方法详解
http://blog.csdn.net/czw2010/article/details/7896264 System.Diagnostics.Process.Start(); 能做什么呢?它主要有以 ...