此文档仅仅是一个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 自定义图片按钮的更多相关文章

  1. WPF 自定义图片剪切器 - 头像剪切(扩展与完善、实时截图)

    原文:WPF 自定义图片剪切器 - 头像剪切(扩展与完善.实时截图) 一.说明:上一次写的"WPF 自定义图片剪切器 - 头像剪切.你懂得"存在明显的缺陷,由于篇幅较长.重新写了一 ...

  2. Mono自定义图片按钮

    首先,我们编写一个MyImageButton类,继承自LinearLayout public class MyPhoneImageButton:LinearLayout { private Image ...

  3. 【WPF】图片按钮的单击与双击事件

    需求:ListBox中的Item是按钮图片,要求单击和双击时触发不同的事件. XAML中需要引入System.Windows.Interactivity.dll xmlns:i="clr-n ...

  4. wpf 自定义Button按钮

    创建ButtonEx类 public class ButtonEx : Button { static ButtonEx() { DefaultStyleKeyProperty.OverrideMet ...

  5. 自己写一个图片按钮(XAML)

    有时需要用三张图片(正常状态,鼠标移上,鼠标按下)来作为一个按钮的样式,虽然这种做法不好,应该用矢量的方式制作样式,但有的时候还是需要这样做的. 每次都修改按钮的样式来实现这个做法,既麻烦又会生成大段 ...

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

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

  7. tableView左划自定义带图片按钮

    本方法实现的原理是将自定义按钮加在tableViewCell.contentView的屏幕外的frame上,打个比方,如果是5系的话,那么你自定义按钮的frame的起点就在(320+,0)(320+表 ...

  8. WPF利用Image实现图片按钮

    之前有一篇文章也是采用了Image实现的图片按钮,不过时间太久远了,忘记了地址.好吧,这里我进行了进一步的改进,原来的文章中需要设置4张图片,分别为可用时,鼠标悬浮时,按钮按下时,按钮不可用时的图片, ...

  9. 【WPF】Button按钮添加背景图片

    只是想做一个很简单的图片按钮而已,不需要那么复杂. <Button x:Name="btn" Width="145" Height="30&qu ...

随机推荐

  1. linux 5个查找命令

    1. find find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件. find的使用格式如下: $ find <指定目录> <指定条件> <指定动作> ...

  2. orientationchange

    <!DOCTYPE html> <html> <head> <title>OrientationChange Event Example</tit ...

  3. spring整合mybatis,springMVC的0配置文件方式

    0配置文件的形式主要是采用spring3.0提供的@configuration注解和spring容器在启动的时候会加载实现了WebApplicationInitializer的类,并调用其onStar ...

  4. css所有属性参考

    学习地址:https://developer.mozilla.org/zh-CN/docs/Web/CSS/Reference

  5. nginx集群tomcat

    一.准备工作 下载nginx,http://nginx.org/,本文采用nginx-1.8.0,下载之后直接解压,免安装 下载tomcat,以配置3台tomcat服务器做负载均衡为例 二.修改tom ...

  6. Raphael初始化,path,circle,rect,ellipse,image

    path jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...

  7. ASP.NET - 自定义控件处理页面事件(控件与页面数据交互)的方法

    //用委托的方法实现 //控件代码 public delegate void DelegateFunction( string sPageTitle ); private DelegateFuncti ...

  8. 在Flex中定义移动设备应用程序和启动屏幕

    创建移动设备应用程序容器 移动设备应用程序中的第一个标签通常是以下标签之一: <s:ViewNavigatorApplication> 标签用于定义只有一个部分的移动设备应用程序. < ...

  9. iOS-如何使用symbolicatecrash

    iOS-如何使用symbolicatecrash 如何使用symbolicatecrash工具分析iOS Crash文件: 原文地址:[iOS Crash文件分析]-如何使用symbolicatecr ...

  10. RAS 加密 解密

    蚂蚁金服电话面试时,问到了RAS加密解密,感觉回答的有点模糊,遂写个例子加深一下印象 package cheng.test.cipher;import java.io.FileInputStream; ...