// 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; public sealed partial class SettingsViewModel() : ViewModel { private bool _isInitialized = false; [ObservableProperty] private string _appVersion = string.Empty; [ObservableProperty] private ThemeType _currentApplicationTheme = ThemeType.Unknow; public override void OnNavigatedTo() { if (!_isInitialized) { InitializeViewModel(); } } partial void OnCurrentApplicationThemeChanged(ThemeType oldValue, ThemeType newValue) { ThemeManager.ChangeAppTheme(newValue); } private void InitializeViewModel() { CurrentApplicationTheme = ThemeManager.GetAppTheme(); AppVersion = $"{GetAssemblyVersion()}"; ThemeManager.Changed += OnThemeChanged; _isInitialized = true; } private void OnThemeChanged(ThemeType currentApplicationTheme, Color systemAccent) { // 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; } }