diff --git a/App.xaml.cs b/App.xaml.cs index 276a3c9..45b405c 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -49,6 +49,7 @@ public partial class App : Application { base.OnStartup(e); ShutdownMode = ShutdownMode.OnExplicitShutdown; + ThemeHelper.InitializeTheme(); await Host.StartAsync(); try diff --git a/Config/ConnectionSettings.cs b/Config/ConnectionSettings.cs index 82e497c..b725148 100644 --- a/Config/ConnectionSettings.cs +++ b/Config/ConnectionSettings.cs @@ -12,6 +12,7 @@ namespace PMSWPF.Config public string UserId { get; set; } = "root"; public string Password { get; set; } = "Pgw15221236646"; public string Database { get; set; } = "pmswpf"; + public string Theme { get; set; } = "跟随系统"; public bool EnableS7Service { get; set; } = true; public bool EnableMqttService { get; set; } = true; public bool EnableOpcUaService { get; set; } = true; diff --git a/ViewModels/SettingViewModel.cs b/ViewModels/SettingViewModel.cs index 1d8705c..b62e043 100644 --- a/ViewModels/SettingViewModel.cs +++ b/ViewModels/SettingViewModel.cs @@ -25,6 +25,24 @@ public partial class SettingViewModel : ViewModelBase _s7BackgroundService = s7BackgroundService; _mqttBackgroundService = mqttBackgroundService; _opcUaBackgroundService = opcUaBackgroundService; + Themes = new List { "浅色", "深色", "跟随系统" }; + } + + public List Themes { get; } + + public string SelectedTheme + { + get => _connectionSettings.Theme; + set + { + if (_connectionSettings.Theme != value) + { + _connectionSettings.Theme = value; + OnPropertyChanged(); + _connectionSettings.Save(); + ThemeHelper.ApplyTheme(value); + } + } } public List AvailableDbTypes { get; set; } @@ -209,4 +227,4 @@ public partial class SettingViewModel : ViewModelBase NotificationHelper.ShowError($"连接失败:{ex.Message}", ex); } } -} \ No newline at end of file +} diff --git a/Views/Dialogs/DeviceDialog.xaml b/Views/Dialogs/DeviceDialog.xaml index 3a80ae4..d1afe0d 100644 --- a/Views/Dialogs/DeviceDialog.xaml +++ b/Views/Dialogs/DeviceDialog.xaml @@ -13,7 +13,6 @@ CloseButtonText="取消" DefaultButton="Primary" PrimaryButtonText="{Binding PrimaryButContent}" - Background="#fff" d:DataContext="{d:DesignInstance vmd:DeviceDialogViewModel}" mc:Ignorable="d"> diff --git a/Views/SettingView.xaml b/Views/SettingView.xaml index 350baf9..fcb9e65 100644 --- a/Views/SettingView.xaml +++ b/Views/SettingView.xaml @@ -15,6 +15,12 @@ + + + diff --git a/Views/VariableTableView.xaml b/Views/VariableTableView.xaml index 8fe796b..de5ecdc 100644 --- a/Views/VariableTableView.xaml +++ b/Views/VariableTableView.xaml @@ -30,7 +30,7 @@