@@ -43,6 +43,10 @@ public partial class MainView : UserControl
4343 private MainViewModel ? _viewModel ;
4444 private readonly Selection _selection ;
4545 private readonly ToolOptionsValues _toolOptionsValues ;
46+ private readonly Image _undoDisabledIcon ;
47+ private readonly Image _undoEnabledIcon ;
48+ private readonly Image _redoDisabledIcon ;
49+ private readonly Image _redoEnabledIcon ;
4650
4751 public MainView ( )
4852 {
@@ -56,13 +60,47 @@ public MainView()
5660 Bitmap . DecodeToWidth ( AssetLoader . Open ( new Uri ( "avares://Scribble/Assets/rotate.png" ) ) , 24 ) ;
5761 SelectionBorder . Cursor = new Cursor ( moveIconBitmap , new PixelPoint ( 18 , 18 ) ) ;
5862 SelectionRotationBtn . Cursor = new Cursor ( rotateIconBitmap , new PixelPoint ( 12 , 12 ) ) ;
63+
64+ _undoDisabledIcon = new Image
65+ {
66+ Source = new Bitmap ( AssetLoader . Open ( new Uri ( "avares://Scribble/Assets/undo-disabled.png" ) ) ) ,
67+ Width = 15 ,
68+ Height = 15 ,
69+ Margin = new Thickness ( 4 )
70+ } ;
71+
72+ _undoEnabledIcon = new Image
73+ {
74+ Source = new Bitmap ( AssetLoader . Open ( new Uri ( "avares://Scribble/Assets/undo.png" ) ) ) ,
75+ Width = 15 ,
76+ Height = 15 ,
77+ Margin = new Thickness ( 4 )
78+ } ;
79+
80+ _redoDisabledIcon = new Image
81+ {
82+ Source = new Bitmap ( AssetLoader . Open ( new Uri ( "avares://Scribble/Assets/redo-disabled.png" ) ) ) ,
83+ Width = 15 ,
84+ Height = 15 ,
85+ Margin = new Thickness ( 4 )
86+ } ;
87+
88+ _redoEnabledIcon = new Image
89+ {
90+ Source = new Bitmap ( AssetLoader . Open ( new Uri ( "avares://Scribble/Assets/redo.png" ) ) ) ,
91+ Width = 15 ,
92+ Height = 15 ,
93+ Margin = new Thickness ( 4 )
94+ } ;
5995 }
6096
6197 protected override void OnDataContextChanged ( EventArgs e )
6298 {
6399 if ( _viewModel != null )
64100 {
65101 _viewModel . RequestInvalidateSelection -= VisualizeSelection ;
102+ _viewModel . UndoStackChanged -= UpdateUndoButton ;
103+ _viewModel . RedoStackChanged -= UpdateRedoButton ;
66104 }
67105
68106 base . OnDataContextChanged ( e ) ;
@@ -71,6 +109,8 @@ protected override void OnDataContextChanged(EventArgs e)
71109 {
72110 _viewModel = viewModel ;
73111 _viewModel . RequestInvalidateSelection += VisualizeSelection ;
112+ _viewModel . UndoStackChanged += UpdateUndoButton ;
113+ _viewModel . RedoStackChanged += UpdateRedoButton ;
74114
75115 Toolbar . Children . Clear ( ) ;
76116
@@ -464,7 +504,8 @@ private void VisualizeSelection()
464504 {
465505 if ( _viewModel == null ) return ;
466506
467- var triggeringSelectionAction = _viewModel . CanvasEvents . Last ( ) is EndSelectionEvent ;
507+ var hasEvents = _viewModel . CanvasEvents . Count > 0 ;
508+ var triggeringSelectionAction = hasEvents && _viewModel . CanvasEvents . Last ( ) is EndSelectionEvent ;
468509 var allSelectedIds = _viewModel . SelectionTargets . Values . SelectMany ( x => x ) . Distinct ( ) . ToList ( ) ;
469510
470511 if ( allSelectedIds . Count > 0 )
@@ -1041,4 +1082,16 @@ private void AboutOption_OnClick(object? sender, RoutedEventArgs e)
10411082 AboutScribbleWindow . IsVisible = true ;
10421083 AboutScribbleWindowOverlay . IsVisible = true ;
10431084 }
1085+
1086+ private void UpdateUndoButton ( int undoStackCount )
1087+ {
1088+ UndoButton . IsEnabled = undoStackCount > 0 ;
1089+ UndoButton . Content = undoStackCount > 0 ? _undoEnabledIcon : _undoDisabledIcon ;
1090+ }
1091+
1092+ private void UpdateRedoButton ( int redoStackCount )
1093+ {
1094+ RedoButton . IsEnabled = redoStackCount > 0 ;
1095+ RedoButton . Content = redoStackCount > 0 ? _redoEnabledIcon : _redoDisabledIcon ;
1096+ }
10441097}
0 commit comments