feat: add RegisterFollowSystemTheme extension.

This commit is contained in:
Zhang Dian
2025-01-07 12:41:51 +08:00
parent af6c52660d
commit ea51867f0f
3 changed files with 81 additions and 39 deletions

View File

@@ -33,9 +33,14 @@ public partial class MainViewModel : ObservableObject
[
new MenuItemViewModel
{
Header = "High Contrast Theme",
Header = "Theme",
Items =
[
new MenuItemViewModel
{
Header = "Auto",
Command = FollowSystemThemeCommand
},
new MenuItemViewModel
{
Header = "Aquatic",
@@ -62,10 +67,10 @@ public partial class MainViewModel : ObservableObject
},
]
},
new MenuItemViewModel()
new MenuItemViewModel
{
Header = "Locale",
Items=
Items =
[
new MenuItemViewModel
{
@@ -114,6 +119,12 @@ public partial class MainViewModel : ObservableObject
];
}
[RelayCommand]
private void FollowSystemTheme()
{
Application.Current?.RegisterFollowSystemTheme();
}
[RelayCommand]
private void ToggleTheme()
{
@@ -121,26 +132,24 @@ public partial class MainViewModel : ObservableObject
if (app is null) return;
var theme = app.ActualThemeVariant;
app.RequestedThemeVariant = theme == ThemeVariant.Dark ? ThemeVariant.Light : ThemeVariant.Dark;
app.UnregisterFollowSystemTheme();
}
[RelayCommand]
private void SelectTheme(object? obj)
{
var app = Application.Current;
if (app is not null)
{
app.RequestedThemeVariant = obj as ThemeVariant;
}
if (app is null) return;
app.RequestedThemeVariant = obj as ThemeVariant;
app.UnregisterFollowSystemTheme();
}
[RelayCommand]
private void SelectLocale(object? obj)
{
var app = Application.Current;
if (app is not null)
{
SemiTheme.OverrideLocaleResources(app, obj as System.Globalization.CultureInfo);
}
if (app is null) return;
SemiTheme.OverrideLocaleResources(app, obj as CultureInfo);
}
[RelayCommand]