diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp index 2936680d..928a5d81 100644 --- a/src/Calculator/App.xaml.cpp +++ b/src/Calculator/App.xaml.cpp @@ -70,6 +70,20 @@ App::App() this->HighContrastAdjustment = ApplicationHighContrastAdjustment::None; this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); + auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting"); + if (value != nullptr) + { + String ^ colorS = safe_cast(value); + // Apply theme choice. + if (colorS == L"Dark") + { + App::Current->RequestedTheme = ApplicationTheme::Dark; + } + else if (colorS == L"Light") + { + App::Current->RequestedTheme = ApplicationTheme::Light; + } + } #if _DEBUG this->DebugSettings->IsBindingTracingEnabled = true; diff --git a/src/Calculator/Resources/en-US/Resources.resw b/src/Calculator/Resources/en-US/Resources.resw index 850db11b..e5a2a3ab 100644 --- a/src/Calculator/Resources/en-US/Resources.resw +++ b/src/Calculator/Resources/en-US/Resources.resw @@ -4770,4 +4770,8 @@ Microsoft Privacy Statment Displayed on a link to the Microsoft Privacy Statement on the Settings page. + + You'll see your changes the next time you start the app. + Notice when the user change the theme. + \ No newline at end of file diff --git a/src/Calculator/SettingsPage.xaml b/src/Calculator/SettingsPage.xaml index 07b3145d..ce82694f 100644 --- a/src/Calculator/SettingsPage.xaml +++ b/src/Calculator/SettingsPage.xaml @@ -17,7 +17,7 @@ MinHeight="{StaticResource HamburgerHeight}" MaxHeight="52"/> - + @@ -32,17 +32,22 @@ AutomationProperties.HeadingLevel="Level1" TextTrimming="Clip"/> + + + Grid.Row="2" + Checked="LightChecked"/> + Grid.Row="3" + Checked="DarkChecked"/> + Grid.Row="4" + Checked="SystemChecked"/> Visibility = Windows::UI::Xaml::Visibility::Collapsed; + Language = locService->GetLanguage(); this->SetVersionString(); this->SetCopyrightString(); + + auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting"); + if (value != nullptr) + { + String ^ colorS = safe_cast(value); + // Apply theme choice. + if (colorS == L"Dark") + { + SettingsDarkTheme->IsChecked = true; + } + else if (Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"isSytemTheme")) + { + SettingsSystemTheme->IsChecked = true; + } + else if (colorS == L"Light") + { + SettingsLightTheme->IsChecked = true; + } + } } void SettingsPage::SetVersionString() @@ -67,3 +88,41 @@ void SettingsPage::SettingsFeedbackButtonClick(_In_ Object ^ sender, _In_ Routed Launcher::LaunchUriAsync(ref new Uri("windows-feedback:?contextid=130&metadata=%7B%22Metadata%22:[%7B%22AppBuild%22:%22" + versionNumber + "%22%7D]%7D")); } + +void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) +{ + auto resourceLoader = AppResourceProvider::GetInstance(); + + SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible; + SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice")); + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString()); +} + +void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) +{ + auto resourceLoader = AppResourceProvider::GetInstance(); + + SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible; + SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice")); + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString()); +} + +void SettingsPage::SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e) +{ + auto resourceLoader = AppResourceProvider::GetInstance(); + auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings(); + auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString(); + + SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible; + SettingsRestartApp->Text = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsRestartNotice")); + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"isSytemTheme", true); + + if (uiTheme == Windows::UI::Colors::Black.ToString()) + { + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString()); + } + else if (uiTheme == Windows::UI::Colors::White.ToString()) + { + Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString()); + } +} diff --git a/src/Calculator/SettingsPage.xaml.h b/src/Calculator/SettingsPage.xaml.h index 14e9a73b..b72952c4 100644 --- a/src/Calculator/SettingsPage.xaml.h +++ b/src/Calculator/SettingsPage.xaml.h @@ -18,5 +18,8 @@ namespace CalculatorApp void SettingsFeedbackButtonClick(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e); void SetVersionString(); void SetCopyrightString(); + void LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); + void SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e); }; }