WPF自定义Button按钮背景,支持鼠标滑动背景,不可用背景

这篇博客介绍了如何在WPF中自定义Button的背景,支持鼠标滑过时背景变化及不可用状态的背景样式。通过定义四个依赖属性,实现了灵活的样式设置,使得样式能适应不同场景。
摘要由CSDN通过智能技术生成

上次在写button实现圆角的时候写了个支持按钮更换背景,支持滑动更换背景和不可用背景的样式。但是写的样式比较死,无法支持一套样式走天下。现在我跟该了下之前写的!

代码如下:

public class SunButton : Button
    {
        #region 属性
        /// <summary>
        /// 圆角
        /// </summary>
        public int BorderRadius
        {
            get { return (int)GetValue(BorderRadiusProperty); }
            set { SetValue(BorderRadiusProperty, value); }

        }

        public static readonly DependencyProperty BorderRadiusProperty = DependencyProperty.Register("BorderRadius", typeof(int), typeof(SunButton),new FrameworkPropertyMetadata());

        /// <summary>
        /// 默认背景
        /// </summary>
        public string DefaultBackground
        {
            get { return (string)GetValue(DefaultBackgroundProperty); }
            set { SetValue(DefaultBackgroundProperty, value); }
        }

        public static readonly DependencyProperty DefaultBackgroundProperty = DependencyProperty.Register("DefaultBackground", typeof(string), typeof(SunButton), new FrameworkPropertyMetadata());


        /// <summary>
        /// 不可用背景
        /// </summary>
        public string EnabledBackground
        {
            get { return (string)GetValue(EnabledBackgroundProperty); }
            set { SetValue(EnabledBackgroundProperty, value); }
        }

        public static readonly DependencyProperty EnabledBackgroundProperty = DependencyProperty.Register("EnabledBackground", typeof(string), typeof(SunButt
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值