使用WPF封装了一个简单的ImageButton自定义控件,加入常态、划过、按下、禁用状态属性,可设置相应的图标。参考链接:https://blog.youkuaiyun.com/elie_yang/article/details/81870694
1、ImageButton自定义控件类
public class UCImageButton : Button
{
static UCImageButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(UCImageButton), new FrameworkPropertyMetadata(typeof(UCImageButton)));
}
#region Properties
public static DependencyProperty NormalImageProperty = DependencyProperty.Register("NormalImage", typeof(ImageSource), typeof(UCImageButton), new PropertyMetadata(null));
public ImageSource NormalImage
{
get { return (ImageSource)GetValue(NormalImageProperty); }
set { SetValue(NormalImageProperty, value); }
}
public static readonly DependencyProperty HoverImageProperty = Depe

本文介绍如何在WPF中封装一个具备多种状态(常态、划过、按下、禁用)的ImageButton控件。详细讲解了控件类的实现、Style样式的编写,特别是针对TemplateBinding在Triggers中的正确用法。同时指出在xaml用法上存在的一个问题,即HoverImage和PressedImage属性未设置时可能出现闪烁,期待解决方案。
最低0.47元/天 解锁文章
317

被折叠的 条评论
为什么被折叠?



