Esempio n. 1
0
        // Adapted from: https://engy.us/blog/2018/10/20/dark-theme-in-wpf/
        private void WatchTheme()
        {
            var    currentUser = WindowsIdentity.GetCurrent();
            string query       = string.Format(
                CultureInfo.InvariantCulture,
                ManagementQuery,
                currentUser.User.Value,
                RegistryKeyPath.Replace(@"\", @"\\"),
                RegistryValueName);

            try
            {
                var watcher = new ManagementEventWatcher(query);
                watcher.EventArrived += (o, e) => _dispatcher.Invoke(() => SystemThemeChanged?.Invoke(this, null));

                // Start listening for events
                watcher.Start();
            }
            catch (Exception)
            {
                // This can fail on Windows 7
            }

            SystemParameters.StaticPropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(SystemParameters.HighContrast))
                {
                    SystemThemeChanged?.Invoke(this, new EventArgs());
                }
            };
        }
Esempio n. 2
0
        private static void UpdateTheme()
        {
            bool isSystemLightTheme = GetIsSystemLightTheme();
            var  args = new SystemThemeChangedEventArgs(isSystemLightTheme);

            SystemThemeChanged?.Invoke(null, args);
        }
        private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
        {
            // This event is raised when the theme is changed,
            // but also for various other irrelevant reasons.
            // Check the registry first, before forcing the application
            // to refresh everything.
            var newTheme = _themeHelper.GetSystemTheme();

            if (newTheme != _currentTheme)
            {
                _currentTheme = newTheme;
                SystemThemeChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Esempio n. 4
0
        private void UpdateColorValues()
        {
            var background = _uiSettings.GetColorValue(UIColorType.Background).ToColor();
            if (_systemBackground != background)
            {
                _systemBackground = background;
                UpdateSystemAppTheme();
                SystemThemeChanged?.Invoke(null, EventArgs.Empty);
            }

            var accent = _uiSettings.GetColorValue(UIColorType.Accent).ToColor();
            if (_systemAccent != accent)
            {
                _systemAccent = accent;
                SystemAccentColorChanged?.Invoke(null, EventArgs.Empty);
            }
        }
Esempio n. 5
0
        private void ListenToSystemColorChanges()
        {
            var uiSettings = new UISettings();

            _systemBackground = uiSettings.GetColorValue(UIColorType.Background).ToColor();
            _systemAccent     = uiSettings.GetColorValue(UIColorType.Accent).ToColor();

            uiSettings.ColorValuesChanged += (sender, args) =>
            {
#if DEBUG
                //for (int i = 0; i <= 8; i++)
                //{
                //    var colorType = (UIColorType)i;
                //    Debug.WriteLine(colorType + " = " + sender.GetColorValue(colorType));
                //}
#endif
                var background = sender.GetColorValue(UIColorType.Background).ToColor();
                if (_systemBackground != background)
                {
                    _systemBackground = background;
                    UpdateSystemAppTheme();
                    SystemThemeChanged?.Invoke(null, EventArgs.Empty);
                }

                var accent = sender.GetColorValue(UIColorType.Accent).ToColor();
                if (_systemAccent != accent)
                {
                    _systemAccent = accent;
                    AccentColorChanged?.Invoke(null, EventArgs.Empty);
                }
            };

            _uiSettings = uiSettings;

            UpdateSystemAppTheme();
        }
Esempio n. 6
0
 public void ManuallyTriggerThemeEvent()
 {
     SystemThemeChanged?.Invoke(this, new EventArgs());
 }
 private void _systemWatcher_EventArrived(object sender, EventArrivedEventArgs e)
 => SystemThemeChanged?.Invoke(null, new ThemeChangedEventArg(GetTheme(ThemeType.System)));
Esempio n. 8
0
 private void ApplicationPreferDarkThemeHandler(object o, GLib.NotifyArgs args)
 => SystemThemeChanged?.Invoke(o, EventArgs.Empty);