本文实例为大家分享了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);
}
}
}
样式代码
调用实例
复制代码 代码如下:
效果展示
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



