forked from lepoco/wpfui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsViewModel.cs
65 lines (50 loc) · 1.81 KB
/
SettingsViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Wpf.Ui.Appearance;
using Wpf.Ui.Abstractions.Controls;
namespace $safeprojectname$.ViewModels.Pages
{
public partial class SettingsViewModel : ObservableObject, INavigationAware
{
private bool _isInitialized = false;
[ObservableProperty]
private string _appVersion = String.Empty;
[ObservableProperty]
private ApplicationTheme _currentTheme = ApplicationTheme.Unknown;
public Task OnNavigatedToAsync()
{
if (!_isInitialized)
InitializeViewModel();
return Task.CompletedTask;
}
public Task OnNavigatedFromAsync() => Task.CompletedTask;
private void InitializeViewModel()
{
CurrentTheme = ApplicationThemeManager.GetAppTheme();
AppVersion = $"UiDesktopApp1 - {GetAssemblyVersion()}";
_isInitialized = true;
}
private string GetAssemblyVersion()
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString()
?? String.Empty;
}
[RelayCommand]
private void OnChangeTheme(string parameter)
{
switch (parameter)
{
case "theme_light":
if (CurrentTheme == ApplicationTheme.Light)
break;
ApplicationThemeManager.Apply(ApplicationTheme.Light);
CurrentTheme = ApplicationTheme.Light;
break;
default:
if (CurrentTheme == ApplicationTheme.Dark)
break;
ApplicationThemeManager.Apply(ApplicationTheme.Dark);
CurrentTheme = ApplicationTheme.Dark;
break;
}
}
}
}