File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1717// DEALINGS IN THE SOFTWARE.
1818
1919using System ;
20+ using System . ComponentModel ;
2021using System . Windows . Input ;
2122
2223namespace ICSharpCode . ILSpy
@@ -35,4 +36,39 @@ public virtual bool CanExecute(object parameter)
3536 return true ;
3637 }
3738 }
39+
40+ public abstract class ToggleableCommand : ICommand , INotifyPropertyChanged
41+ {
42+ private bool isChecked ;
43+
44+ public event EventHandler CanExecuteChanged {
45+ add { CommandManager . RequerySuggested += value ; }
46+ remove { CommandManager . RequerySuggested -= value ; }
47+ }
48+
49+ public event PropertyChangedEventHandler PropertyChanged ;
50+
51+ void ICommand . Execute ( object parameter )
52+ {
53+ IsChecked = Execute ( parameter ) ;
54+ }
55+
56+ public bool IsChecked {
57+ get => isChecked ;
58+ set {
59+ if ( isChecked != value )
60+ {
61+ isChecked = value ;
62+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( nameof ( IsChecked ) ) ) ;
63+ }
64+ }
65+ }
66+
67+ public abstract bool Execute ( object parameter ) ;
68+
69+ public virtual bool CanExecute ( object parameter )
70+ {
71+ return true ;
72+ }
73+ }
3874}
Original file line number Diff line number Diff line change 2929using System . Threading . Tasks ;
3030using System . Windows ;
3131using System . Windows . Controls ;
32+ using System . Windows . Data ;
3233using System . Windows . Input ;
3334using System . Windows . Interop ;
3435using System . Windows . Media ;
@@ -299,6 +300,12 @@ void InitMainMenu()
299300 }
300301
301302 menuItem . IsEnabled = entry . Metadata . IsEnabled ;
303+ if ( entry . Value is ToggleableCommand toggle )
304+ {
305+ menuItem . IsCheckable = true ;
306+ menuItem . SetBinding ( MenuItem . IsCheckedProperty , new Binding ( "IsChecked" ) { Source = entry . Value , Mode = BindingMode . OneWay } ) ;
307+ }
308+
302309 menuItem . InputGestureText = entry . Metadata . InputGestureText ;
303310 parentMenuItem . Items . Add ( menuItem ) ;
304311 }
You can’t perform that action at this time.
0 commit comments