您现在的位置是:网站首页> 编程资料编程资料
WPF图片按钮的实现方法_实用技巧_
2023-05-24
317人已围观
简介 WPF图片按钮的实现方法_实用技巧_
本文实例为大家分享了WPF图片按钮的实现代码,供大家参考,具体内容如下
直接代码
public class ImageButton : System.Windows.Controls.Button { /// /// 图片 /// public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(null)); /// /// 图片的宽度 /// public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register("ImageWidth", typeof(double), typeof(ImageButton), new PropertyMetadata(double.NaN)); /// /// 图片的高度 /// public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(double), typeof(ImageButton), new PropertyMetadata(double.NaN)); /// /// 构造函数 /// static ImageButton() { DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new System.Windows.FrameworkPropertyMetadata(typeof(ImageButton))); } /// /// 设置图片 /// public ImageSource Image { get { return GetValue(ImageProperty) as ImageSource; } set { SetValue(ImageProperty, value); } } /// /// 图片宽度(属性) /// public double ImageWidth { get { return (double)GetValue(ImageWidthProperty); } set { SetValue(ImageWidthProperty, value); } } /// /// 图片高度(属性) /// public double ImageHeight { get { return (double)GetValue(ImageHeightProperty); } set { SetValue(ImageHeightProperty, value); } } } 样式代码
调用实例
复制代码 代码如下:
效果展示

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
相关内容
- 浅谈ASP.NET Core 2.0 带初始参数的中间件(译)_实用技巧_
- 浅谈ASP.NET Core 2.0 中间件(译)_实用技巧_
- .NET发送邮件遇到问题及解决方法_实用技巧_
- ASP.NET Core 2.0 带初始参数的中间件问题及解决方法_实用技巧_
- ASP.NET页面之间传值的方式之Application实例详解_实用技巧_
- asp.net mvc webapi 实用的接口加密方法示例_实用技巧_
- 使用重绘项美化WinForm的控件_实用技巧_
- ASP.NET MVC API 接口验证的示例代码_实用技巧_
- EntityFramework 6.x学习之多个上下文迁移实现分布式事务详解_实用技巧_
- ASP.NET MVC4异步聊天室的示例代码_实用技巧_
