更新整理
This commit is contained in:
73
WPFluent.Gallery/ViewModels/Pages/SettingsViewModel.cs
Normal file
73
WPFluent.Gallery/ViewModels/Pages/SettingsViewModel.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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;
|
||||
using WPFluent.Controls;
|
||||
using WPFluent.Extensions;
|
||||
|
||||
namespace WPFluent.Gallery.ViewModels.Pages;
|
||||
|
||||
public sealed partial class SettingsViewModel(INavigationService navigationService) : ViewModel
|
||||
{
|
||||
private bool _isInitialized = false;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _appVersion = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private ApplicationTheme _currentApplicationTheme = ApplicationTheme.Unknown;
|
||||
|
||||
[ObservableProperty]
|
||||
private NavigationViewPaneDisplayMode _currentApplicationNavigationStyle =
|
||||
NavigationViewPaneDisplayMode.Left;
|
||||
|
||||
public override void OnNavigatedTo()
|
||||
{
|
||||
if (!_isInitialized)
|
||||
{
|
||||
InitializeViewModel();
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnCurrentApplicationThemeChanged(ApplicationTheme oldValue, ApplicationTheme newValue)
|
||||
{
|
||||
ApplicationThemeManager.Apply(newValue);
|
||||
}
|
||||
|
||||
partial void OnCurrentApplicationNavigationStyleChanged(
|
||||
NavigationViewPaneDisplayMode oldValue,
|
||||
NavigationViewPaneDisplayMode newValue
|
||||
)
|
||||
{
|
||||
_ = navigationService.SetPaneDisplayMode(newValue);
|
||||
}
|
||||
|
||||
private void InitializeViewModel()
|
||||
{
|
||||
CurrentApplicationTheme = ApplicationThemeManager.GetAppTheme();
|
||||
AppVersion = $"{GetAssemblyVersion()}";
|
||||
|
||||
ApplicationThemeManager.Changed += OnThemeChanged;
|
||||
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
private void OnThemeChanged(ApplicationTheme 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user