WPF图片按钮的实现
            
            
                    
                        标签:dev   win   必须   template   ide   stat   保留   按钮   targe   
直接代码
 1  public class ImageButton : System.Windows.Controls.Button
 2     {
 3 
 4         /// 
 5         /// 图片
 6         /// 
 7         public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(ImageButton),
 8             new PropertyMetadata(null));
 9 
10         /// 
11         /// 图片的宽度
12         /// 
13         public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register("ImageWidth", typeof(double), typeof(ImageButton),
14             new PropertyMetadata(double.NaN));
15 
16         /// 
17         /// 图片的高度
18         /// 
19         public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(double), typeof(ImageButton),
20             new PropertyMetadata(double.NaN));
21 
22         /// 
23         /// 构造函数
24         /// 
25         static ImageButton()
26         {
27             DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), 
28                 new System.Windows.FrameworkPropertyMetadata(typeof(ImageButton)));
29         }
30 
31         /// 
32         /// 设置图片
33         /// 
34         public ImageSource Image
35         {
36             get
37             {
38                 return GetValue(ImageProperty) as ImageSource;
39             }
40             set
41             {
42                 SetValue(ImageProperty, value);
43             }
44         }
45 
46         /// 
47         /// 图片宽度(属性)
48         /// 
49         public double ImageWidth
50         {
51             get
52             {
53                 return (double)GetValue(ImageWidthProperty);
54             }
55             set
56             {
57                 SetValue(ImageWidthProperty, value);
58             }
59         }
60 
61         /// 
62         /// 图片高度(属性)
63         /// 
64         public double ImageHeight
65         {
66             get
67             {
68                 return (double)GetValue(ImageHeightProperty);
69             }
70             set
71             {
72                 SetValue(ImageHeightProperty, value);
73             }
74         }
75 
76     }
 
样式代码
调用实例
1     "../Image/设置.png" Content="新增会员" ImageHeight="52" ImageWidth="52" Width="72" Height="72" Margin="30,10,10,10"/>
 
效果展示

本文原创出处:http://www.cnblogs.com/PettyHandSome/
欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利!
WPF图片按钮的实现
标签:dev   win   必须   template   ide   stat   保留   按钮   targe   
原文地址:http://www.cnblogs.com/PettyHandSome/p/7717908.html
                    
             
            
            
            
            
                
                    文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
                    文章标题:
WPF图片按钮的实现
                    文章链接:http://soscw.com/index.php/essay/82257.html                
 
            
                                
评论