From cf870afe48bb9134616e8dce1a6c88da785cce48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=EC=98=81?= Date: Mon, 1 Apr 2024 18:57:09 +0900 Subject: [PATCH] =?UTF-8?q?[build]=20=EA=B5=90=EC=9C=A1=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EC=A0=9D=ED=8A=B8=20=EC=B4=88=EC=95=88=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이 커밋에서는 WPF 애플리케이션의 초기 구성과 관련된 여러 가지 중요한 변경사항들이 이루어졌습니다. 주요 변경사항은 다음과 같습니다: 1. `App.xaml`에서 애플리케이션의 시작점을 `StartupUri`에서 `Startup` 이벤트로 변경하였습니다. 이를 통해 애플리케이션 시작 시 보다 세밀한 컨트롤이 가능해졌습니다. 2. `App.xaml.cs`에서 `OnStartup` 메서드 대신 `Application_Startup` 메서드를 사용하도록 변경하였고, `Main` 메서드의 주석 처리된 부분을 삭제하여 코드를 정리하였습니다. 또한, 테마와 언어 설정을 위한 메서드들의 접근 제한자를 `private`에서 `static`으로 변경하여 클래스 레벨에서 접근 가능하게 하였습니다. 3. `AppSettings.cs`에서 발생한 변수명 오류를 수정하여, 이벤트 아규먼트의 `Old` 값을 `language`에서 `theme`으로 정확히 반영하도록 하였습니다. 4. `MemberInputPanel.xaml`에서 정적 리소스 대신 동적 리소스를 사용하도록 변경하여, 런타임에 리소스 변경이 가능하게 하였습니다. 5. 사용되지 않는 `AlreadyExcutedAppException.cs` 파일을 삭제하여 프로젝트의 깔끔함을 유지하였습니다. 6. `MainWindowViewModel.cs`와 `RegistMemberWindowViewModel.cs`에서 코드 정리를 수행하고, 윈도우 최소화, 최대화, 닫기 등의 기능을 수행하는 커맨드를 추가하였습니다. 7. `LoginWindow.xaml`과 `MainWindow.xaml`에서 정적 리소스를 동적 리소스로 변경하여 언어 및 테마 변경 시 UI가 동적으로 업데이트 되도록 개선했습니다. 이러한 변경사항들은 애플리케이션의 시작 과정을 보다 유연하게 만들고, 사용자 인터페이스의 동적 업데이트를 가능하게 하며, 전반적인 코드의 정리와 개선을 목표로 합니다. --- src/WPFEduSolution/WPFBeginner/App.xaml | 2 +- src/WPFEduSolution/WPFBeginner/App.xaml.cs | 67 +++++++++---------- .../WPFBeginner/Configurations/AppSettings.cs | 2 +- .../Controls/MemberInputPanel.xaml | 8 +-- .../Exceptions/AlreadyExcutedAppException.cs | 16 ----- .../ViewModels/MainWindowViewModel.cs | 65 +++++++++++------- .../ViewModels/RegistMemberWindowViewModel.cs | 4 ++ .../WPFBeginner/Views/LoginWindow.xaml | 4 +- .../WPFBeginner/Views/MainWindow.xaml | 56 +++++++++++----- .../WPFBeginner/Views/RegistMemberWindow.xaml | 2 +- 10 files changed, 123 insertions(+), 103 deletions(-) delete mode 100644 src/WPFEduSolution/WPFBeginner/Exceptions/AlreadyExcutedAppException.cs diff --git a/src/WPFEduSolution/WPFBeginner/App.xaml b/src/WPFEduSolution/WPFBeginner/App.xaml index 502643e..f239d22 100644 --- a/src/WPFEduSolution/WPFBeginner/App.xaml +++ b/src/WPFEduSolution/WPFBeginner/App.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:service="clr-namespace:WPFBeginner.Services" xmlns:conv="clr-namespace:WPFBeginner.Converters" - StartupUri="/Views/MainWindow.xaml"> + Startup="Application_Startup"> diff --git a/src/WPFEduSolution/WPFBeginner/App.xaml.cs b/src/WPFEduSolution/WPFBeginner/App.xaml.cs index 6e9bd5b..49d7ffc 100644 --- a/src/WPFEduSolution/WPFBeginner/App.xaml.cs +++ b/src/WPFEduSolution/WPFBeginner/App.xaml.cs @@ -26,38 +26,34 @@ namespace WPFBeginner public static AppSettings Config { get; private set; } - //[STAThread] - //static void Main() - //{ - //try - //{ - // var application = new App(); - // application.InitializeComponent(); // For resouce load. - // application.Run(); - //} - //catch (AlreadyExcutedAppException ex) - //{ - // MessageBox.Show("이미 실행중입니다. 종료 후, 다시 실행해주세요"); - //} - //catch (LoginFailedException ex) - //{ - // // Do not anything; - //} - //catch (Exception ex) - //{ - // // log - //} - //} - - protected override void OnStartup(StartupEventArgs e) + private void Application_Startup(object sender, StartupEventArgs e) { - base.OnStartup(e); - - //Login(); InitializeService(); + var main = new MainWindow(); + App.Current.MainWindow = main; + try + { + Login(); + + Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; + App.Current.MainWindow.Show(); + } + catch(Exception ex) + { + App.Current.MainWindow.Close(); + Environment.Exit(0); + } } - private void InitializeService() + private void UnhandledExceptionHandle(object e) + { + if(e is UnhandledExceptionEventArgs uee && uee.ExceptionObject is LoginFailedException) + { + + } + } + + private static void InitializeService() { Config = JsonSerializer.Deserialize(File.ReadAllText("appsettings.json")); @@ -78,22 +74,22 @@ namespace WPFBeginner .BuildServiceProvider()); } - private void SetTheme(string code) + private static void SetTheme(string code) { if (_currentTheme != null) - Resources.MergedDictionaries.Remove(_currentTheme); + App.Current.Resources.MergedDictionaries.Remove(_currentTheme); _currentTheme = ResourceExplorer.GetThemeResourceDic(code); - Resources.MergedDictionaries.Add(_currentTheme); + App.Current.Resources.MergedDictionaries.Add(_currentTheme); } - private void SetLanguage(string code) + private static void SetLanguage(string code) { if (_currentLanguage != null) - Resources.MergedDictionaries.Remove( _currentLanguage ); + App.Current.Resources.MergedDictionaries.Remove( _currentLanguage ); _currentLanguage = ResourceExplorer.GetLanguageResourceDic(code); - Resources.MergedDictionaries.Add(_currentLanguage); + App.Current.Resources.MergedDictionaries.Add(_currentLanguage); } private static void Login() @@ -101,9 +97,10 @@ namespace WPFBeginner var login = new LoginWindow(); var isSuccess = login.ShowDialog(); - if (isSuccess != true) + if (isSuccess != true) throw new LoginFailedException(); } } } + diff --git a/src/WPFEduSolution/WPFBeginner/Configurations/AppSettings.cs b/src/WPFEduSolution/WPFBeginner/Configurations/AppSettings.cs index 45a9963..d58bf69 100644 --- a/src/WPFEduSolution/WPFBeginner/Configurations/AppSettings.cs +++ b/src/WPFEduSolution/WPFBeginner/Configurations/AppSettings.cs @@ -48,7 +48,7 @@ namespace WPFBeginner.Configurations { var eventArg = new StringChangedEventArg() { - Old = language, + Old = theme, New = value }; diff --git a/src/WPFEduSolution/WPFBeginner/Controls/MemberInputPanel.xaml b/src/WPFEduSolution/WPFBeginner/Controls/MemberInputPanel.xaml index 243b793..b6f1aca 100644 --- a/src/WPFEduSolution/WPFBeginner/Controls/MemberInputPanel.xaml +++ b/src/WPFEduSolution/WPFBeginner/Controls/MemberInputPanel.xaml @@ -39,10 +39,10 @@ -