From 6e6970630666c6a9cab5f39e83c565b49505cfdc Mon Sep 17 00:00:00 2001 From: Hikari Liou Date: Fri, 1 Dec 2023 00:12:02 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=B0=87=E9=BB=91=E6=9A=97=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E7=94=B1=20Switch=20=E6=94=B9=E7=82=BA=20Picker=20?= =?UTF-8?q?=E5=9E=8B=E6=85=8B=E4=B8=A6=E6=96=B0=E5=A2=9E"=E8=B7=9F?= =?UTF-8?q?=E9=9A=A8=E7=B3=BB=E7=B5=B1=E9=A0=90=E8=A8=AD"=E7=9A=84?= =?UTF-8?q?=E9=A1=8F=E8=89=B2=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DateCalculator/MainPage.xaml | 11 +++++++++++ src/DateCalculator/MainPage.xaml.cs | 24 +++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/DateCalculator/MainPage.xaml b/src/DateCalculator/MainPage.xaml index 302f0c4..99371c7 100644 --- a/src/DateCalculator/MainPage.xaml +++ b/src/DateCalculator/MainPage.xaml @@ -9,6 +9,17 @@ Spacing="25" Padding="30,0" VerticalOptions="Center"> + + + + 亮色模式 + 暗色模式 + 跟隨系統預設 + + + diff --git a/src/DateCalculator/MainPage.xaml.cs b/src/DateCalculator/MainPage.xaml.cs index f428f8e..c70e654 100644 --- a/src/DateCalculator/MainPage.xaml.cs +++ b/src/DateCalculator/MainPage.xaml.cs @@ -225,10 +225,28 @@ private void UIReset() DateDiffDatePicker.IsVisible = false; } - private void OnDarkModeToggled(object sender, ToggledEventArgs e) + // private void OnDarkModeToggled(object sender, ToggledEventArgs e) + // { + // if (Application.Current != null) + // Application.Current.UserAppTheme = Application.Current.UserAppTheme is AppTheme.Light ? AppTheme.Dark : AppTheme.Light; + // } + + private void OnDarkModePickerSelected(object sender, EventArgs e) { - if (Application.Current != null) - Application.Current.UserAppTheme = Application.Current.UserAppTheme is AppTheme.Light ? AppTheme.Dark : AppTheme.Light; + var selectedMode = (sender as Picker).SelectedItem.ToString(); + + if (selectedMode == "亮色模式") + { + Application.Current.UserAppTheme = AppTheme.Light; + } + else if (selectedMode == "暗色模式") + { + Application.Current.UserAppTheme = AppTheme.Dark; + } + else if (selectedMode == "跟隨系統預設") + { + Application.Current.UserAppTheme = AppTheme.Unspecified; + } } } } \ No newline at end of file From 0ebc8ddbdc14fad8a8f37c0e35ddf4f96be6880c Mon Sep 17 00:00:00 2001 From: Hikari Liou Date: Sun, 3 Dec 2023 19:50:49 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1.=E5=B0=87=E9=BB=91=E5=A4=9C=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E7=94=B1Picker=E6=94=B9=E5=9B=9ESwitch=E5=BD=A2?= =?UTF-8?q?=E5=BC=8F=202.=E5=88=9D=E6=AD=A5=E4=BF=AE=E6=AD=A3=E9=A1=8F?= =?UTF-8?q?=E8=89=B2=E5=88=87=E6=8F=9B=E6=9C=83=E8=AE=8A=E7=A9=BA=E7=99=BD?= =?UTF-8?q?=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DateCalculator/MainPage.xaml | 16 ++---- src/DateCalculator/MainPage.xaml.cs | 89 +++++++++++++++++++---------- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/DateCalculator/MainPage.xaml b/src/DateCalculator/MainPage.xaml index 99371c7..1a460f6 100644 --- a/src/DateCalculator/MainPage.xaml +++ b/src/DateCalculator/MainPage.xaml @@ -9,17 +9,11 @@ Spacing="25" Padding="30,0" VerticalOptions="Center"> - - - - 亮色模式 - 暗色模式 - 跟隨系統預設 - - - + + diff --git a/src/DateCalculator/MainPage.xaml.cs b/src/DateCalculator/MainPage.xaml.cs index c70e654..a8f200e 100644 --- a/src/DateCalculator/MainPage.xaml.cs +++ b/src/DateCalculator/MainPage.xaml.cs @@ -1,4 +1,8 @@ using System.Globalization; +using System.Runtime.InteropServices; +using Microsoft.UI; +using Microsoft.UI.Xaml.Controls; +using Windows.Devices.HumanInterfaceDevice; namespace DateCalculator { @@ -20,13 +24,13 @@ public MainPage() SetDefault(); if (Application.Current != null) - Application.Current.UserAppTheme = AppTheme.Light; + Application.Current.UserAppTheme = Application.Current.RequestedTheme; } private void OnADBtnClicked(object sender, EventArgs e) { isTwYear = false; - + ADBtn.BackgroundColor = toggledBackgroundColor; TWBtn.BackgroundColor = defaultTWBtnBackgroundColor; } @@ -34,7 +38,7 @@ private void OnADBtnClicked(object sender, EventArgs e) private void OnTWBtnClicked(object sender, EventArgs e) { isTwYear = true; - + ADBtn.BackgroundColor = defaultADBtnBackgroundColor; TWBtn.BackgroundColor = toggledBackgroundColor; } @@ -149,11 +153,6 @@ private void SetDefault() isCalculateDays = false; isFront = false; - defaultADBtnBackgroundColor = ADBtn.BackgroundColor; - defaultTWBtnBackgroundColor = TWBtn.BackgroundColor; - defaultFrontBtnBackgroundColor = FrontBtn.BackgroundColor; - defaultBackBtnBackgroundColor = BackBtn.BackgroundColor; - defaultDiffBtnBackgroundColor = DiffBtn.BackgroundColor; toggledBackgroundColor = Color.FromRgb(255, 82, 82); } @@ -208,11 +207,10 @@ private void UIReset() DateSelectDatePicker.Date = DateTime.Now; DateDiffDatePicker.Date = DateTime.Now; - ADBtn.BackgroundColor = defaultADBtnBackgroundColor; - TWBtn.BackgroundColor = defaultTWBtnBackgroundColor; - FrontBtn.BackgroundColor = defaultFrontBtnBackgroundColor; - BackBtn.BackgroundColor = defaultBackBtnBackgroundColor; - DiffBtn.BackgroundColor = defaultDiffBtnBackgroundColor; + if(Application.Current.UserAppTheme == AppTheme.Light) + LightMode(); + else + DarkMode(); YearEntry.Text = null; MonthEntry.Text = null; @@ -224,29 +222,62 @@ private void UIReset() DayEntry.IsVisible = true; DateDiffDatePicker.IsVisible = false; } - - // private void OnDarkModeToggled(object sender, ToggledEventArgs e) - // { - // if (Application.Current != null) - // Application.Current.UserAppTheme = Application.Current.UserAppTheme is AppTheme.Light ? AppTheme.Dark : AppTheme.Light; - // } - - private void OnDarkModePickerSelected(object sender, EventArgs e) + + private void OnDarkModeToggled(object sender, ToggledEventArgs e) { - var selectedMode = (sender as Picker).SelectedItem.ToString(); - - if (selectedMode == "亮色模式") + if (Application.Current != null) + Application.Current.UserAppTheme = Application.Current.UserAppTheme is AppTheme.Light ? AppTheme.Dark : AppTheme.Light; + + if (Application.Current.UserAppTheme == AppTheme.Light) { - Application.Current.UserAppTheme = AppTheme.Light; + LightMode(); } - else if (selectedMode == "暗色模式") + else { - Application.Current.UserAppTheme = AppTheme.Dark; + DarkMode(); } - else if (selectedMode == "跟隨系統預設") + } + + private void LightMode() + { + var hasLightColor = App.Current.Resources.TryGetValue("Primary", out var color); + + if (hasLightColor) { - Application.Current.UserAppTheme = AppTheme.Unspecified; + var primaryColor = (Color)color; + defaultADBtnBackgroundColor = primaryColor; + defaultTWBtnBackgroundColor = primaryColor; + defaultFrontBtnBackgroundColor = primaryColor; + defaultBackBtnBackgroundColor = primaryColor; + defaultDiffBtnBackgroundColor = primaryColor; } + + TWBtn.BackgroundColor = defaultTWBtnBackgroundColor; + ADBtn.BackgroundColor = defaultADBtnBackgroundColor; + FrontBtn.BackgroundColor = defaultFrontBtnBackgroundColor; + BackBtn.BackgroundColor = defaultBackBtnBackgroundColor; + DiffBtn.BackgroundColor = defaultDiffBtnBackgroundColor; + } + + private void DarkMode() + { + var hasDarkColor = App.Current.Resources.TryGetValue("Secondary", out var color); + + if (hasDarkColor) + { + var secondaryColor = (Color)color; + defaultADBtnBackgroundColor = secondaryColor; + defaultTWBtnBackgroundColor = secondaryColor; + defaultFrontBtnBackgroundColor = secondaryColor; + defaultBackBtnBackgroundColor = secondaryColor; + defaultDiffBtnBackgroundColor = secondaryColor; + } + + TWBtn.BackgroundColor = defaultTWBtnBackgroundColor; + ADBtn.BackgroundColor = defaultADBtnBackgroundColor; + FrontBtn.BackgroundColor = defaultFrontBtnBackgroundColor; + BackBtn.BackgroundColor = defaultBackBtnBackgroundColor; + DiffBtn.BackgroundColor = defaultDiffBtnBackgroundColor; } } } \ No newline at end of file From c7b83f1ba8092f2684079a8571f801d029c75500 Mon Sep 17 00:00:00 2001 From: Hikari Liou Date: Tue, 5 Dec 2023 22:45:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=B7=B2=E5=B0=87Switch=E7=8B=80=E6=85=8B?= =?UTF-8?q?=E5=9B=BA=E5=AE=9A=E7=82=BA=E9=97=9C=E9=96=89=E6=99=82=E7=82=BA?= =?UTF-8?q?=E6=98=8E=E4=BA=AE=E6=A8=A1=E5=BC=8F=EF=BC=8C=E9=96=8B=E5=95=9F?= =?UTF-8?q?=E7=82=BA=E9=BB=91=E6=9A=97=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DateCalculator/MainPage.xaml.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/DateCalculator/MainPage.xaml.cs b/src/DateCalculator/MainPage.xaml.cs index a8f200e..8e87676 100644 --- a/src/DateCalculator/MainPage.xaml.cs +++ b/src/DateCalculator/MainPage.xaml.cs @@ -24,7 +24,16 @@ public MainPage() SetDefault(); if (Application.Current != null) - Application.Current.UserAppTheme = Application.Current.RequestedTheme; + Application.Current.UserAppTheme = Application.Current.RequestedTheme; + + if (Application.Current.RequestedTheme == AppTheme.Light) + { + DarkModeSwitch.IsToggled = false; + } + else + { + DarkModeSwitch.IsToggled = true; + } } private void OnADBtnClicked(object sender, EventArgs e) @@ -226,8 +235,17 @@ private void UIReset() private void OnDarkModeToggled(object sender, ToggledEventArgs e) { if (Application.Current != null) - Application.Current.UserAppTheme = Application.Current.UserAppTheme is AppTheme.Light ? AppTheme.Dark : AppTheme.Light; - + Application.Current.UserAppTheme = Application.Current.RequestedTheme is AppTheme.Light ? AppTheme.Dark : AppTheme.Light; + + if (DarkModeSwitch.IsToggled) + { + Application.Current.UserAppTheme = AppTheme.Dark; + } + else + { + Application.Current.UserAppTheme = AppTheme.Light; + } + if (Application.Current.UserAppTheme == AppTheme.Light) { LightMode(); From bb63aa9426110378076a23c8ce427b04b09c9b08 Mon Sep 17 00:00:00 2001 From: Hikari Liou Date: Wed, 13 Dec 2023 00:15:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=89=88=E9=9D=A2=E5=BE=AE=E8=AA=BF?= =?UTF-8?q?=E8=88=87=E5=AD=97=E9=AB=94=E9=A1=8F=E8=89=B2=E8=AA=BF=E6=95=B4?= =?UTF-8?q?=E7=82=BA=E6=98=8E=E4=BA=AE=E6=A8=A1=E5=BC=8F=E6=88=96=E9=BB=91?= =?UTF-8?q?=E6=9A=97=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9A=86=E7=82=BA=E7=99=BD?= =?UTF-8?q?=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 14 ++++++++++++++ src/DateCalculator/MainPage.xaml | 6 +++--- src/DateCalculator/MainPage.xaml.cs | 10 +++++++--- src/DateCalculator/Resources/Styles/Colors.xaml | 1 + src/DateCalculator/Resources/Styles/Styles.xaml | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7e9926e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // 使用 IntelliSense 以得知可用的屬性。 + // 暫留以檢視現有屬性的描述。 + // 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET MAUI", + "type": "maui", + "request": "launch", + "preLaunchTask": "maui: Build" + } + ] +} \ No newline at end of file diff --git a/src/DateCalculator/MainPage.xaml b/src/DateCalculator/MainPage.xaml index 1a460f6..4bac9a2 100644 --- a/src/DateCalculator/MainPage.xaml +++ b/src/DateCalculator/MainPage.xaml @@ -44,7 +44,7 @@ x:Name="DateSelectDatePicker" FontSize="24" HorizontalOptions="Center" - Format="yyyy 年 MM 月 dd 日" + Format="yyyy / MM / dd " Margin="20" /> @@ -115,7 +115,7 @@ x:Name="DateDiffDatePicker" FontSize="24" HorizontalOptions="Center" - Format="yyyy 年 MM 月 dd 日" + Format="yyyy / MM / dd " Margin="20" IsVisible="false"/>