mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Theme functionality
This commit is contained in:
parent
80549804e4
commit
6cc0b32faf
5 changed files with 89 additions and 4 deletions
|
@ -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<String ^>(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;
|
||||
|
|
|
@ -4770,4 +4770,8 @@
|
|||
<value>Microsoft Privacy Statment</value>
|
||||
<comment>Displayed on a link to the Microsoft Privacy Statement on the Settings page.</comment>
|
||||
</data>
|
||||
<data name="SettingsRestartNotice" xml:space="preserve">
|
||||
<value>You'll see your changes the next time you start the app.</value>
|
||||
<comment>Notice when the user change the theme.</comment>
|
||||
</data>
|
||||
</root>
|
|
@ -17,7 +17,7 @@
|
|||
MinHeight="{StaticResource HamburgerHeight}"
|
||||
MaxHeight="52"/>
|
||||
<RowDefinition Height="4*"/>
|
||||
<RowDefinition Height="1*" MaxHeight="32"/>
|
||||
<RowDefinition Height="Auto" MinHeight="32"/>
|
||||
<RowDefinition Height="4*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
|
@ -32,17 +32,22 @@
|
|||
AutomationProperties.HeadingLevel="Level1"
|
||||
TextTrimming="Clip"/>
|
||||
|
||||
<TextBlock x:Name="SettingsRestartApp" Style="{StaticResource BodyTextBlockStyle}"/>
|
||||
|
||||
<RadioButton x:Name="SettingsLightTheme"
|
||||
x:Uid="SettingsLightTheme"
|
||||
Grid.Row="2"/>
|
||||
Grid.Row="2"
|
||||
Checked="LightChecked"/>
|
||||
|
||||
<RadioButton x:Name="SettingsDarkTheme"
|
||||
x:Uid="SettingsDarkTheme"
|
||||
Grid.Row="3"/>
|
||||
Grid.Row="3"
|
||||
Checked="DarkChecked"/>
|
||||
|
||||
<RadioButton x:Name="SettingsSystemTheme"
|
||||
x:Uid="SettingsSystemTheme"
|
||||
Grid.Row="4"/>
|
||||
Grid.Row="4"
|
||||
Checked="SystemChecked"/>
|
||||
|
||||
<HyperlinkButton x:Name="ColorSettingsButton"
|
||||
Margin="0,-2"
|
||||
|
|
|
@ -32,10 +32,31 @@ SettingsPage::SettingsPage()
|
|||
|
||||
InitializeComponent();
|
||||
|
||||
SettingsRestartApp->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<String ^>(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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue