1- using System . Windows . Input ;
2-
3- namespace Codebreaker . ViewModels ;
1+ namespace Codebreaker . ViewModels . Components ;
42
53public enum InfoMessageSeverity
64{
@@ -10,82 +8,38 @@ public enum InfoMessageSeverity
108 Error
119}
1210
13- public partial class InfoMessageViewModel : ObservableObject
11+ public partial class InfoMessageViewModel ( Action closeAction ) : ObservableObject
1412{
15- public static InfoMessageViewModel Error ( string content )
16- {
17- InfoMessageViewModel message = new ( )
18- {
19- Title = "Error" ,
20- Message = content ,
21- Severity = InfoMessageSeverity . Error ,
22- ActionTitle = "OK"
23- } ;
24- message . ActionCommand = new RelayCommand ( ( ) => message . Close ( ) ) ;
25- return message ;
26- }
27-
28- public static InfoMessageViewModel Warning ( string content )
29- {
30- InfoMessageViewModel message = new ( )
31- {
32- Title = "Warning" ,
33- Message = content ,
34- Severity = InfoMessageSeverity . Warning ,
35- ActionTitle = "OK"
36- } ;
37- message . ActionCommand = new RelayCommand ( ( ) => message . Close ( ) ) ;
38- return message ;
39- }
40-
41- public static InfoMessageViewModel Information ( string content )
42- {
43- InfoMessageViewModel message = new ( )
44- {
45- Title = "Information" ,
46- Message = content ,
47- Severity = InfoMessageSeverity . Info ,
48- ActionTitle = "OK"
49- } ;
50- message . ActionCommand = new RelayCommand ( ( ) => message . Close ( ) ) ;
51- return message ;
52- }
53-
54- public static InfoMessageViewModel Success ( string content )
55- {
56- InfoMessageViewModel message = new ( )
57- {
58- Title = "Success" ,
59- Message = content ,
60- Severity = InfoMessageSeverity . Success ,
61- ActionTitle = "OK"
62- } ;
63- message . ActionCommand = new RelayCommand ( ( ) => message . Close ( ) ) ;
64- return message ;
65- }
66-
67- internal ICollection < InfoMessageViewModel > ? ContainingCollection { get ; set ; }
68-
6913 [ ObservableProperty ]
70- private InfoMessageSeverity _severity = InfoMessageSeverity . Info ;
14+ private InfoMessageSeverity _severity ;
7115
7216 [ ObservableProperty ]
7317 private string _message = string . Empty ;
7418
7519 [ ObservableProperty ]
76- private string _title = string . Empty ;
20+ private string ? _title ;
7721
7822 [ ObservableProperty ]
7923 [ NotifyPropertyChangedFor ( nameof ( HasAction ) ) ]
80- private ICommand ? _actionCommand ;
24+ [ NotifyCanExecuteChangedFor ( nameof ( ExecuteActionCommand ) ) ]
25+ private Action ? _action ;
26+
27+ [ RelayCommand ]
28+ public void ExecuteAction ( ) => Action ? . Invoke ( ) ;
8129
8230 [ ObservableProperty ]
8331 [ NotifyPropertyChangedFor ( nameof ( HasAction ) ) ]
84- private string ? _actionTitle = "OK" ;
32+ private string ? _actionText = "OK" ;
8533
86- public bool HasAction =>
87- ActionCommand is not null && ActionTitle is not null ;
34+ public bool HasAction => ExecuteActionCommand is not null && ActionText is not null ;
8835
89- public void Close ( ) =>
90- ContainingCollection ? . Remove ( this ) ;
91- }
36+ [ ObservableProperty ]
37+ [ NotifyCanExecuteChangedFor ( nameof ( CloseCommand ) ) ]
38+ private Action _closeAction = closeAction ;
39+
40+ [ ObservableProperty ]
41+ private bool _isClosable ;
42+
43+ [ RelayCommand ]
44+ public void Close ( ) => CloseAction ( ) ;
45+ }
0 commit comments