Skip to content

Commit 5578571

Browse files
committed
fix: updated code to use mvvmToolkit features
1 parent 50268af commit 5578571

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

reference/SimpleCalc/MVVM-CSharp/SimpleCalculator/MainViewModel.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
2-
using CommunityToolkit.Mvvm.Input;
3-
41
namespace SimpleCalculator;
52

63
public partial class MainViewModel : ObservableObject
74
{
8-
private readonly IThemeService _themeService;
5+
private readonly IThemeService _themeService;
96

10-
private bool _isDark;
11-
public bool IsDark
12-
{
13-
get => _isDark;
14-
set
15-
{
16-
if (SetProperty(ref _isDark, value))
17-
{
18-
_themeService.SetThemeAsync(value ? AppTheme.Dark : AppTheme.Light);
19-
}
20-
}
21-
}
7+
[ObservableProperty]
8+
private bool _isDark;
9+
10+
partial void OnIsDarkChanged(bool value) =>
11+
_themeService.SetThemeAsync(value ? AppTheme.Dark : AppTheme.Light);
2212

2313
public MainViewModel(IThemeService themeService)
2414
{

reference/SimpleCalc/MVVM-Xaml/SimpleCalculator/MainViewModel.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
using CommunityToolkit.Mvvm.ComponentModel;
2-
using CommunityToolkit.Mvvm.Input;
3-
41
namespace SimpleCalculator;
52

63
public partial class MainViewModel : ObservableObject
74
{
8-
private readonly IThemeService _themeService;
5+
private readonly IThemeService _themeService;
96

10-
private bool _isDark;
11-
public bool IsDark
12-
{
13-
get => _isDark;
14-
set
15-
{
16-
if (SetProperty(ref _isDark, value))
17-
{
18-
_themeService.SetThemeAsync(value ? AppTheme.Dark : AppTheme.Light);
19-
}
20-
}
21-
}
7+
[ObservableProperty]
8+
private bool _isDark;
9+
10+
partial void OnIsDarkChanged(bool value) =>
11+
_themeService.SetThemeAsync(value ? AppTheme.Dark : AppTheme.Light);
2212

2313
public MainViewModel(IThemeService themeService)
2414
{

0 commit comments

Comments
 (0)