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 ...
随机推荐
- Oracle的一些命令
sqlldr: 一般用于导入以任何后缀结束的文件,我这次就是因为要导入一张以.20160101为后缀的文件,当初简直束手无策 结合input.ctl使用,可以在DOS下使用,可以对一张表导入数十万,百 ...
- Poi2006 Palindromes
2780: Poi2006 Palindromes Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 15 Solved: 5[Submit][Stat ...
- bzoj1070————2016——3——14
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1070: 题目概括: Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中 ...
- mac 画图
1.1.XMind 基础功能免费试用 1.2.OmniGraflle 可以跳转之类的,比较方便的,类似于可以制作原型图 Omnigraffle Pro 6 Name: mojadoSerial: JY ...
- php常用图片处理类
<?php /** * 已知问题:1.在图片缩放功能中,使用imagecreatetruecolor函数创建画布,并使用透明处理算法,但PNG格式的图片无法透明.用imagecreate函数创建 ...
- 将[4,3,2,5,4,3]分割成[4,3,2]、[5,4,3]两个List的算法
将[4,3,2,5,4,3]分割成[4,3,2].[5,4,3]两个List的算法 package com.srie.test; import java.util.ArrayList; import ...
- PWM(脉宽调制)——LED特效呼吸灯设计
简述PWM PWM--脉宽调制信号(Pulse Width Modulation),它利用微处理器的数字输出来实现,是对模拟电路控制的一种非常有效的技术,广泛应用于测量.通信.功率控制与变化等许多领域 ...
- Bootstrap入门(二十二)组件16:列表组
Bootstrap入门(二十二)组件16:列表组 列表组是灵活又强大的组件,不仅能用于显示一组简单的元素,还能用于复杂的定制的内容. 1.默认样式列表组 2.加入徽章 3.链接 4.禁用的列表组 5. ...
- 二分查找 - vb.net
Module Module1 Sub Main() Dim array(999) As Integer Dim searchValue As Integer ...
- EF6的多线程与分库架构设计实现
1.项目背景 这里简单介绍一下项目需求背景,之前公司的项目基于EF++Repository+UnitOfWork的框架设计的,其中涉及到的技术有RabbitMq消息队列,Autofac依赖注入等常用的 ...