Does RaiseCanExecuteChanged need to be called on the UI thread? #78
Answered
by
brminnick
CodingOctocat
asked this question in
Q&A
-
I found this question at StackOverflow, should the RaiseCanExecuteChanged method be executed on the UI thread instead? Why people use CommandManager.InvalidateRequerySuggested() on ICommands? - StackOverflow
|
Beta Was this translation helpful? Give feedback.
Answered by
brminnick
Jun 8, 2021
Replies: 1 comment 5 replies
-
Hi @CodingOctocat! The answer is "It Depends". Non UI FrameworksNo, you do not need to marshall UI FrameworksIf you are using a UI dependent framework, such as WinForms, WPF, Xamarin, etc., AND
Xamarin Examplepublic IAsyncCommand ButtonCommand { get; } = new AsyncCommand(ExecuteButtonCommand);
static async Task ExecuteButtonCommand()
{
// Handle Button Command
}
void OnCanExecuteChanged() => Device.BeginInvokeOnMainThread(ButtonCommand.RaiseCanExecuteChanged); |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
CodingOctocat
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @CodingOctocat!
The answer is "It Depends".
Non UI Frameworks
No, you do not need to marshall
RaiseCanExecuteChanged
to the main threadUI Frameworks
If you are using a UI dependent framework, such as WinForms, WPF, Xamarin, etc.,
AND
ICommand
is bound to a UI control (eg aButton
), then yes you will need to invokeRaiseCanExecuteChanged
on the main thread:Xamarin Example