博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF 自定义IconButton
阅读量:7063 次
发布时间:2019-06-28

本文共 1333 字,大约阅读时间需要 4 分钟。

原文:

自定义一个按钮控件

按钮控件很简单,我们在项目中有时把样式封装起来,添加依赖属性,也是为了统一。

这里举例,单纯的图标控件怎么设置

1、UserControl界面样式

2、后台设置,我这边只添加了个图片路径和事件委托。其它的自己加吧

public partial class IconButton : UserControl    {        public IconButton()        {            InitializeComponent();        }        public ImageSource ImagesSource        {            get { return (ImageSource)GetValue(ImagesSourceProperty); }            set { SetValue(ImagesSourceProperty, value); }        }        public static readonly DependencyProperty ImagesSourceProperty = DependencyProperty.Register("ImagesSource",        typeof(ImageSource), typeof(IconButton));        private void IconButton_OnLoaded(object sender, RoutedEventArgs e)        {            var data = new IconButtonModel()            {                ImagesSource = ImagesSource            };            this.DataContext = data;        }        public delegate void ClickEventArgs(object sender, RoutedEventArgs e);        public event ClickEventArgs Click;        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)        {            if (Click != null)            {                Click(sender, e);            }        }    }    public class IconButtonModel    {        public ImageSource ImagesSource { get; set; }    }
View Code

 

转载地址:http://tiill.baihongyu.com/

你可能感兴趣的文章
Java中的代理
查看>>
顺序表的静态建立
查看>>
Java反射(Reflection)获取运行时类的结构
查看>>
来美国一年半了,命里有时终须有,命里无时莫强求(2)
查看>>
swiper轮播图(逆向自动切换类似于无限循环)
查看>>
阿里云域名解析+网站备案
查看>>
转载文章 RESIZING WIN32 DIALOGS
查看>>
开发规范(一) 如何记录日志 By 阿里
查看>>
1117bootstrap
查看>>
centos6.5上卸载和安装JDK7
查看>>
从文件加载至NSData
查看>>
Java连接访问Oracle--Connection.setSavepoint()方法使用
查看>>
LeetCode OJ:Maximal Square(最大矩形)
查看>>
抽象工厂 C++实现
查看>>
[KMP]字符串匹配算法
查看>>
[转] 随机数是骗人的,.Net、Java、C为我作证
查看>>
第一天
查看>>
VUE基础插值表达式
查看>>
如何在mysql客户端即mysql提示符下执行操作系统命令
查看>>
人月神话读后感
查看>>