mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-15 05:36:34 +08:00
feat: add RegisterFollowSystemTheme extension.
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user