WPF如何实现图片按钮-创新互联

这篇文章给大家分享的是有关WPF如何实现图片按钮的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

成都创新互联公司是专业的龙文网站建设公司,龙文接单;提供做网站、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行龙文网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

,具体内容如下

直接代码

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);
  }
 }

 }

样式代码


 
  
  
   
   
    
    
   
   
   
   
   
   
   
    
   
   

  
  
 
 

调用实例

复制代码 代码如下:

 

效果展示

WPF如何实现图片按钮

感谢各位的阅读!关于“WPF如何实现图片按钮”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


网站标题:WPF如何实现图片按钮-创新互联
网站地址:http://scyanting.com/article/cdhshe.html