Skip to content

Commit

Permalink
Updated CanExecuteChanged in NativeMenuItem.cs to thunk to the UI thr…
Browse files Browse the repository at this point in the history
…ead if it ends up running on a non-UI thread.
  • Loading branch information
logiclrd committed Jun 13, 2024
1 parent b17729d commit c71d999
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Avalonia.Controls/NativeMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Input;
using Avalonia.Media.Imaging;
using Avalonia.Metadata;
using Avalonia.Threading;
using Avalonia.Utilities;

namespace Avalonia.Controls
Expand Down Expand Up @@ -164,7 +165,10 @@ public bool IsVisible

void CanExecuteChanged()
{
SetCurrentValue(IsEnabledProperty, Command?.CanExecute(CommandParameter) ?? true);
if (!Dispatcher.UIThread.CheckAccess())
Dispatcher.UIThread.Invoke(() => CanExecuteChanged());
else
SetCurrentValue(IsEnabledProperty, Command?.CanExecute(CommandParameter) ?? true);
}

public bool HasClickHandlers => Click != null;
Expand Down

0 comments on commit c71d999

Please sign in to comment.