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

本文共 1456 字,大约阅读时间需要 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

 

posted on
2018-09-25 08:55 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/lonelyxmas/p/9697813.html

你可能感兴趣的文章