From 5915a6c87bcee7808fa3a92d374ca8152f7ba34e Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Wed, 9 Jul 2025 20:48:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=98=AF=E5=90=A6=E6=9C=80=E5=B0=8F=E5=8C=96?= =?UTF-8?q?=E5=88=B0=E9=80=9A=E7=9F=A5=E6=A0=8F=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/ConnectionSettings.cs | 1 + ViewModels/SettingViewModel.cs | 14 ++++++++++++++ Views/MainView.xaml.cs | 14 +++++++++++--- Views/SettingView.xaml | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Config/ConnectionSettings.cs b/Config/ConnectionSettings.cs index b568a76..82e497c 100644 --- a/Config/ConnectionSettings.cs +++ b/Config/ConnectionSettings.cs @@ -15,6 +15,7 @@ namespace PMSWPF.Config public bool EnableS7Service { get; set; } = true; public bool EnableMqttService { get; set; } = true; public bool EnableOpcUaService { get; set; } = true; + public bool MinimizeToTrayOnClose { get; set; } = true; private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "connectionSettings.json"); diff --git a/ViewModels/SettingViewModel.cs b/ViewModels/SettingViewModel.cs index 7a4751a..1d8705c 100644 --- a/ViewModels/SettingViewModel.cs +++ b/ViewModels/SettingViewModel.cs @@ -179,6 +179,20 @@ public partial class SettingViewModel : ViewModelBase } } + public bool MinimizeToTrayOnClose + { + get => _connectionSettings.MinimizeToTrayOnClose; + set + { + if (_connectionSettings.MinimizeToTrayOnClose != value) + { + _connectionSettings.MinimizeToTrayOnClose = value; + OnPropertyChanged(nameof(MinimizeToTrayOnClose)); + _connectionSettings.Save(); + } + } + } + [RelayCommand] private async Task TestConnection() { diff --git a/Views/MainView.xaml.cs b/Views/MainView.xaml.cs index 11c70ee..83925e6 100644 --- a/Views/MainView.xaml.cs +++ b/Views/MainView.xaml.cs @@ -33,9 +33,17 @@ public partial class MainView : Window private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - // Hide the window instead of closing it - e.Cancel = true; - Hide(); + var settings = Config.ConnectionSettings.Load(); + if (settings.MinimizeToTrayOnClose) + { + // Hide the window instead of closing it + e.Cancel = true; + Hide(); + } + else + { + Application.Current.Shutdown(); + } } public void ShowApplication() diff --git a/Views/SettingView.xaml b/Views/SettingView.xaml index cfea5a9..350baf9 100644 --- a/Views/SettingView.xaml +++ b/Views/SettingView.xaml @@ -9,6 +9,19 @@ d:DesignHeight="450" d:DesignWidth="800"> + + + + + + + + + + + +