Skip to content

Commit cff8728

Browse files
committed
adjust baseCommand to accept new source generation
1 parent 81a9465 commit cff8728

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

SimpleViewModel/BaseClasses/BaseCommand.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows.Input;
1+
using System.Windows;
2+
using System.Windows.Input;
23

34
namespace SimpleViewModel.BaseClasses;
45

@@ -16,6 +17,18 @@ public event EventHandler? CanExecuteChanged
1617
remove => CommandManager.RequerySuggested -= value;
1718
}
1819

20+
/// <summary>
21+
/// Forces WPF to re-evaluate <see cref="CanExecute"/> for all commands.
22+
/// Safe to call from any thread — marshals to the UI dispatcher if needed.
23+
/// </summary>
24+
public void RaiseCanExecuteChanged()
25+
{
26+
if (Application.Current?.Dispatcher.CheckAccess() == true)
27+
CommandManager.InvalidateRequerySuggested();
28+
else
29+
Application.Current?.Dispatcher.Invoke(CommandManager.InvalidateRequerySuggested);
30+
}
31+
1932
/// <summary>
2033
/// Determines whether the command can execute in its current state.
2134
/// </summary>

SimpleViewModel/SimpleViewModel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<PackageId>SimpleViewModel</PackageId>
12-
<Version>0.9.8.3</Version>
12+
<Version>0.9.8.4</Version>
1313
<Authors>Derek Gooding</Authors>
1414
<Company>Derek Gooding</Company>
1515
<Description>

0 commit comments

Comments
 (0)