ColorHelper DevExpress

本类实现了应用程序主题颜色的管理功能,通过监听主题变化并更新背景和前景颜色来确保UI的一致性。支持默认主题颜色设置,并能根据不同的主题名称调整颜色。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class ColorHelper : INotifyPropertyChanged
    {

        static SolidColorBrush DefaultThemeBackgroundColor

= new SolidColorBrush(Color.FromRgb(0xA3, 0xC3, 0xEC));
        static SolidColorBrush DefaultThemeForegroundColor

= new SolidColorBrush(Color.FromRgb(0x00, 0x00, 0x00));

        public ColorHelper()
        {
            ThemeManager.ThemeChanged +=

ColorHelper.ThemeChanged;
            GetColors

(ThemeManager.ActualApplicationThemeName);
        }
        private Brush _Foreground;
        private Brush _Background;
        static ColorHelper _Instance;
        public static ColorHelper Instance { get { if

(_Instance == null)_Instance = new ColorHelper(); return

_Instance; } }

        public Brush Background
        {
            get { return _Background; }
            set
            {
                if (_Background == value)
                    return;
                _Background = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new

PropertyChangedEventArgs("Background"));
            }
        }
        public Brush Foreground
        {
            get { return _Foreground; }
            set
            {
                if (_Foreground == value)
                    return;
                _Foreground = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new

PropertyChangedEventArgs("Foreground"));
            }
        }

        public static void ThemeChanged(DependencyObject

sender, ThemeChangedRoutedEventArgs e)
        {
            Instance.GetColors(e.ThemeName);
        }

        void GetColors(string name)
        {
            if (name == "DeepBlue")
            {
                Background = DefaultThemeBackgroundColor;
                Foreground = DefaultThemeForegroundColor;
                return;
            }
            ThemeManager.ThemeChanged -=

ColorHelper.ThemeChanged;
            BackgroundPanel p = new BackgroundPanel();
            ThemeManager.SetThemeName(p, name);
            var q = p.Background;
            Background = p.Background;
            Foreground = p.Foreground;
            ThemeManager.ThemeChanged +=

ColorHelper.ThemeChanged;
        }

        public event PropertyChangedEventHandler

PropertyChanged;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值