Bean/HighContrastHelper.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System.ComponentModel;
using System.Windows;
using System.Windows.Media;

namespace XStart2._0.Bean {
    public class HighContrastHelper : DependencyObject {
        private HighContrastHelper() {
            SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged;
        }

        ~HighContrastHelper() {
            SystemParameters.StaticPropertyChanged -= SystemParameters_StaticPropertyChanged;
        }

        private static HighContrastHelper instance;
        public static HighContrastHelper Instance {
            get {
                if (instance == null)
                    instance = new HighContrastHelper();
                return instance;
            }
        }

        public void ApplyCurrentTheme() {
            if (SystemParameters.HighContrast) {
                SolidColorBrush windowbrush = SystemColors.WindowBrush;
                if (windowbrush.Color.R == 255 && windowbrush.Color.G == 255 && windowbrush.Color.B == 255) {
                    Instance.IsHighContrastWhite = true;
                    Instance.IsHighContrastBlack = false;
                } else if (windowbrush.Color.R == 0 && windowbrush.Color.G == 0 && windowbrush.Color.B == 0) {
                    Instance.IsHighContrastWhite = false;
                    Instance.IsHighContrastBlack = true;
                } else {
                    Instance.IsHighContrastWhite = false;
                    Instance.IsHighContrastBlack = false;
                }
            }
        }

        void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e) {
            if (e.PropertyName == "HighContrast") {
                ApplyCurrentTheme();
            }
        }

        public static readonly DependencyProperty IsHighContrastWhiteProperty = DependencyProperty.Register(
            "IsHighContrastWhite",
            typeof(bool),
            typeof(HighContrastHelper),
            new PropertyMetadata(false));

        public static readonly DependencyProperty IsHighContrastBlackProperty = DependencyProperty.Register(
            "IsHighContrastBlack",
            typeof(bool),
            typeof(HighContrastHelper),
            new PropertyMetadata(false));

        public bool IsHighContrastWhite {
            get { return (bool)GetValue(IsHighContrastWhiteProperty); }
            private set { SetValue(IsHighContrastWhiteProperty, value); }
后面还有 8 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。