File tree Expand file tree Collapse file tree 2 files changed +12
-32
lines changed
MVVM-CSharp/SimpleCalculator
MVVM-Xaml/SimpleCalculator Expand file tree Collapse file tree 2 files changed +12
-32
lines changed Original file line number Diff line number Diff line change 1
- using CommunityToolkit . Mvvm . ComponentModel ;
2
- using CommunityToolkit . Mvvm . Input ;
3
-
4
1
namespace SimpleCalculator ;
5
2
6
3
public partial class MainViewModel : ObservableObject
7
4
{
8
- private readonly IThemeService _themeService ;
5
+ private readonly IThemeService _themeService ;
9
6
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 ) ;
22
12
23
13
public MainViewModel ( IThemeService themeService )
24
14
{
Original file line number Diff line number Diff line change 1
- using CommunityToolkit . Mvvm . ComponentModel ;
2
- using CommunityToolkit . Mvvm . Input ;
3
-
4
1
namespace SimpleCalculator ;
5
2
6
3
public partial class MainViewModel : ObservableObject
7
4
{
8
- private readonly IThemeService _themeService ;
5
+ private readonly IThemeService _themeService ;
9
6
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 ) ;
22
12
23
13
public MainViewModel ( IThemeService themeService )
24
14
{
You can’t perform that action at this time.
0 commit comments