mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
Add more themeing functionality
This commit is contained in:
parent
9f2d3e7949
commit
7195ebe9cf
4 changed files with 33 additions and 38 deletions
|
@ -71,18 +71,31 @@ App::App()
|
|||
|
||||
this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
|
||||
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
||||
auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
|
||||
auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
|
||||
if (value != nullptr)
|
||||
{
|
||||
String ^ colorS = safe_cast<String ^>(value);
|
||||
String ^ colorSetting = safe_cast<String ^>(value);
|
||||
// Apply theme choice.
|
||||
if (colorS == L"Dark")
|
||||
if (colorSetting == L"Dark")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
||||
}
|
||||
else if (colorS == L"Light")
|
||||
else if (colorSetting == L"Light")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Light;
|
||||
}
|
||||
else if (colorSetting == L"System")
|
||||
{
|
||||
if (uiTheme == "#FF000000")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
||||
}
|
||||
else if (uiTheme == "#FFFFFFFF")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if _DEBUG
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "App.g.h"
|
||||
#include "WindowFrameService.h"
|
||||
#include "SettingsPage.g.h"
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
MinHeight="{StaticResource HamburgerHeight}"
|
||||
MaxHeight="52"/>
|
||||
<RowDefinition Height="4*"/>
|
||||
<RowDefinition Height="Auto" MinHeight="32"/>
|
||||
<RowDefinition Height="Auto" MaxHeight="32"/>
|
||||
<RowDefinition Height="4*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
@ -34,16 +34,16 @@
|
|||
|
||||
<TextBlock x:Name="SettingsRestartApp" Style="{StaticResource BodyTextBlockStyle}"/>
|
||||
|
||||
<RadioButton x:Name="SettingsLightTheme"
|
||||
x:Uid="SettingsLightTheme"
|
||||
Grid.Row="2"
|
||||
Checked="LightChecked"/>
|
||||
|
||||
<RadioButton x:Name="SettingsDarkTheme"
|
||||
x:Uid="SettingsDarkTheme"
|
||||
Grid.Row="3"
|
||||
Grid.Row="2"
|
||||
Checked="DarkChecked"/>
|
||||
|
||||
<RadioButton x:Name="SettingsLightTheme"
|
||||
x:Uid="SettingsLightTheme"
|
||||
Grid.Row="3"
|
||||
Checked="LightChecked"/>
|
||||
|
||||
<RadioButton x:Name="SettingsSystemTheme"
|
||||
x:Uid="SettingsSystemTheme"
|
||||
Grid.Row="4"
|
||||
|
|
|
@ -24,11 +24,11 @@ using namespace Windows::UI::Xaml::Data;
|
|||
#define BUILD_YEAR 2020
|
||||
#endif
|
||||
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
|
||||
SettingsPage::SettingsPage()
|
||||
{
|
||||
auto locService = LocalizationService::GetInstance();
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -42,20 +42,19 @@ SettingsPage::SettingsPage()
|
|||
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
||||
if (value != nullptr)
|
||||
{
|
||||
String ^ colorS = safe_cast<String ^>(value);
|
||||
// Apply theme choice.
|
||||
if (colorS == L"Dark")
|
||||
String ^ colorSetting = safe_cast<String ^>(value);
|
||||
if (colorSetting == L"Dark")
|
||||
{
|
||||
SettingsDarkTheme->IsChecked = true;
|
||||
}
|
||||
else if (Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"isSytemTheme"))
|
||||
{
|
||||
SettingsSystemTheme->IsChecked = true;
|
||||
}
|
||||
else if (colorS == L"Light")
|
||||
else if (colorSetting == L"Light")
|
||||
{
|
||||
SettingsLightTheme->IsChecked = true;
|
||||
}
|
||||
else if (colorSetting == L"System")
|
||||
{
|
||||
SettingsSystemTheme->IsChecked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +68,6 @@ void SettingsPage::SetVersionString()
|
|||
|
||||
void SettingsPage::SetCopyrightString()
|
||||
{
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
auto copyrightText = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
|
||||
|
||||
SettingsCopyright->Text = copyrightText;
|
||||
|
@ -91,8 +89,6 @@ void SettingsPage::SettingsFeedbackButtonClick(_In_ Object ^ sender, _In_ Routed
|
|||
|
||||
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());
|
||||
|
@ -100,8 +96,6 @@ void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::Ro
|
|||
|
||||
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());
|
||||
|
@ -109,20 +103,7 @@ void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::Rou
|
|||
|
||||
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());
|
||||
}
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", L"System");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue