From 1bd42653e98e77bf656a6a70cff754600266d522 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:35:59 +0100 Subject: [PATCH] Implement theme switcher and fix some bugs --- .../DataContexts/MainWindowDataContext.cs | 5 ++- src/InvLock/MainWindow.xaml | 31 ++++++++++++++----- src/InvLock/Settings.cs | 27 ++++++++++++++++ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/InvLock/DataContexts/MainWindowDataContext.cs b/src/InvLock/DataContexts/MainWindowDataContext.cs index 65e5860..136f959 100644 --- a/src/InvLock/DataContexts/MainWindowDataContext.cs +++ b/src/InvLock/DataContexts/MainWindowDataContext.cs @@ -1,9 +1,8 @@ -using System.ComponentModel; -using System.Reflection; +using System.Reflection; namespace InvLock.DataContexts; -internal class MainWindowDataContext : INotifyPropertyChanged +internal class MainWindowDataContext { #if DEBUG public string Title => $"{App.AppName} - Dev {AppVersion}"; diff --git a/src/InvLock/MainWindow.xaml b/src/InvLock/MainWindow.xaml index e2b90ba..b547b02 100644 --- a/src/InvLock/MainWindow.xaml +++ b/src/InvLock/MainWindow.xaml @@ -76,7 +76,7 @@ - + @@ -129,7 +129,26 @@ - + + + + + + + + + + + + + + + + + + + + @@ -140,13 +159,9 @@ - - + + - - - - diff --git a/src/InvLock/Settings.cs b/src/InvLock/Settings.cs index 33a03ee..33bc1d8 100644 --- a/src/InvLock/Settings.cs +++ b/src/InvLock/Settings.cs @@ -3,6 +3,8 @@ using System.IO; using System.Runtime.CompilerServices; using System.Text.Json; +using Wpf.Ui.Appearance; + namespace InvLock; public class Settings : INotifyPropertyChanged @@ -12,6 +14,7 @@ public class Settings : INotifyPropertyChanged private static readonly string settingsPath = Path.Combine(App.ApplicationDataPath, "settings.json"); private bool hideWindows = false; private string lockText = "Lock Screen Active"; + private string theme = "Windows default"; private string unlockText = "Lock Screen Inactive"; @@ -45,6 +48,30 @@ public class Settings : INotifyPropertyChanged } } + public string Theme + { + get => theme; + set + { + theme = value; + + if (value == "Windows default") + { + ApplicationThemeManager.ApplySystemTheme(); + } + else if (value == "Light") + { + ApplicationThemeManager.Apply(ApplicationTheme.Light); + } + else if (value == "Dark") + { + ApplicationThemeManager.Apply(ApplicationTheme.Dark); + } + + OnPropertyChanged(); + } + } + public static Settings Load() { if (File.Exists(settingsPath))