1
1
using System . Diagnostics ;
2
+ using CommunityToolkit . Mvvm . ComponentModel ;
3
+ using CommunityToolkit . Mvvm . Input ;
2
4
using MaterialDesignThemes . Wpf ;
3
5
4
6
namespace MaterialDesignDemo . Domain ;
5
7
6
- public class DialogsViewModel : ViewModelBase
8
+ public partial class DialogsViewModel : ObservableObject
7
9
{
8
- public DialogsViewModel ( )
9
- {
10
- //Sample 4
11
- OpenSample4DialogCommand = new AnotherCommandImplementation ( OpenSample4Dialog ) ;
12
- AcceptSample4DialogCommand = new AnotherCommandImplementation ( AcceptSample4Dialog ) ;
13
- CancelSample4DialogCommand = new AnotherCommandImplementation ( CancelSample4Dialog ) ;
14
- }
15
-
16
10
#region SAMPLE 3
17
11
18
- public ICommand RunDialogCommand => new AnotherCommandImplementation ( ExecuteRunDialog ) ;
19
-
20
- public ICommand RunExtendedDialogCommand => new AnotherCommandImplementation ( ExecuteRunExtendedDialog ) ;
21
-
22
- private async void ExecuteRunDialog ( object ? _ )
12
+ [ RelayCommand ]
13
+ private async Task RunDialog ( )
23
14
{
24
15
//let's set up a little MVVM, cos that's what the cool kids are doing:
25
- var view = new SampleDialog
16
+ object ? view = new SampleDialog
26
17
{
27
18
DataContext = new SampleDialogViewModel ( )
28
19
} ;
29
20
30
21
//show the dialog
31
- var result = await DialogHost . Show ( view , "RootDialog" , null , ClosingEventHandler , ClosedEventHandler ) ;
22
+ object ? result = await DialogHost . Show ( view , "RootDialog" , null , ClosingEventHandler , ClosedEventHandler ) ;
32
23
33
24
//check the result...
34
25
Debug . WriteLine ( "Dialog was closed, the CommandParameter used to close it was: " + ( result ?? "NULL" ) ) ;
@@ -40,16 +31,17 @@ private void ClosingEventHandler(object sender, DialogClosingEventArgs eventArgs
40
31
private void ClosedEventHandler ( object sender , DialogClosedEventArgs eventArgs )
41
32
=> Debug . WriteLine ( "You can intercept the closed event here (1)." ) ;
42
33
43
- private async void ExecuteRunExtendedDialog ( object ? _ )
34
+ [ RelayCommand ]
35
+ private async Task RunExtendedDialog ( )
44
36
{
45
37
//let's set up a little MVVM, cos that's what the cool kids are doing:
46
- var view = new SampleDialog
38
+ object ? view = new SampleDialog
47
39
{
48
40
DataContext = new SampleDialogViewModel ( )
49
41
} ;
50
42
51
43
//show the dialog
52
- var result = await DialogHost . Show ( view , "RootDialog" , ExtendedOpenedEventHandler , ExtendedClosingEventHandler , ExtendedClosedEventHandler ) ;
44
+ object ? result = await DialogHost . Show ( view , "RootDialog" , ExtendedOpenedEventHandler , ExtendedClosingEventHandler , ExtendedClosedEventHandler ) ;
53
45
54
46
//check the result...
55
47
Debug . WriteLine ( "Dialog was closed, the CommandParameter used to close it was: " + ( result ?? "NULL" ) ) ;
@@ -84,35 +76,26 @@ private void ExtendedClosedEventHandler(object sender, DialogClosedEventArgs eve
84
76
85
77
#region SAMPLE 4
86
78
87
- //pretty much ignore all the stuff provided, and manage everything via custom commands and a binding for .IsOpen
88
- public ICommand OpenSample4DialogCommand { get ; }
89
- public ICommand AcceptSample4DialogCommand { get ; }
90
- public ICommand CancelSample4DialogCommand { get ; }
79
+ //pretty much ignore all the stuff provided, and manage everything via custom commands and a binding for .IsOpen
91
80
92
- private bool _isSample4DialogOpen ;
81
+ [ ObservableProperty ]
93
82
private object ? _sample4Content ;
94
83
95
- public bool IsSample4DialogOpen
96
- {
97
- get => _isSample4DialogOpen ;
98
- set => SetProperty ( ref _isSample4DialogOpen , value ) ;
99
- }
100
-
101
- public object ? Sample4Content
102
- {
103
- get => _sample4Content ;
104
- set => SetProperty ( ref _sample4Content , value ) ;
105
- }
106
-
107
- private void OpenSample4Dialog ( object ? _ )
84
+ [ ObservableProperty ]
85
+ private bool _isSample4DialogOpen ;
86
+
87
+ [ RelayCommand ]
88
+ private void OpenSample4Dialog ( )
108
89
{
109
90
Sample4Content = new Sample4Dialog ( ) ;
110
91
IsSample4DialogOpen = true ;
111
92
}
112
93
113
- private void CancelSample4Dialog ( object ? _ ) => IsSample4DialogOpen = false ;
94
+ [ RelayCommand ]
95
+ private void CancelSample4Dialog ( ) => IsSample4DialogOpen = false ;
114
96
115
- private void AcceptSample4Dialog ( object ? _ )
97
+ [ RelayCommand ]
98
+ private void AcceptSample4Dialog ( )
116
99
{
117
100
//pretend to do something for 3 seconds, then close
118
101
Sample4Content = new SampleProgressDialog ( ) ;
0 commit comments