Files
ShrlAlgoToolkit/WPFluent.Gallery/ViewModels/Pages/SettingsViewModel.cs

61 lines
1.7 KiB
C#
Raw Normal View History

2025-04-24 20:56:44 +08:00
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
using System.Reflection;
using System.Windows.Media;
using WPFluent.Appearance;
namespace WPFluent.Gallery.ViewModels.Pages;
2025-05-05 17:04:06 +08:00
public sealed partial class SettingsViewModel() : ViewModel
2025-04-24 20:56:44 +08:00
{
private bool _isInitialized = false;
[ObservableProperty]
private string _appVersion = string.Empty;
[ObservableProperty]
2025-05-05 17:04:06 +08:00
private ThemeType _currentApplicationTheme = ThemeType.Unknow;
2025-04-24 20:56:44 +08:00
public override void OnNavigatedTo()
{
if (!_isInitialized)
{
InitializeViewModel();
}
}
2025-05-05 17:04:06 +08:00
partial void OnCurrentApplicationThemeChanged(ThemeType oldValue, ThemeType newValue)
2025-04-24 20:56:44 +08:00
{
2025-05-05 17:04:06 +08:00
ThemeManager.ChangeAppTheme(newValue);
2025-04-24 20:56:44 +08:00
}
private void InitializeViewModel()
{
2025-05-05 17:04:06 +08:00
CurrentApplicationTheme = ThemeManager.GetAppTheme();
2025-04-24 20:56:44 +08:00
AppVersion = $"{GetAssemblyVersion()}";
2025-05-05 17:04:06 +08:00
ThemeManager.Changed += OnThemeChanged;
2025-04-24 20:56:44 +08:00
_isInitialized = true;
}
2025-05-05 17:04:06 +08:00
private void OnThemeChanged(ThemeType currentApplicationTheme, Color systemAccent)
2025-04-24 20:56:44 +08:00
{
// Update the theme if it has been changed elsewhere than in the settings.
if (CurrentApplicationTheme != currentApplicationTheme)
{
CurrentApplicationTheme = currentApplicationTheme;
}
}
private static string GetAssemblyVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? string.Empty;
}
}