Only then did I discover there’s an MSDN Docs sample called “Disable Command Source Via Dispatcher Timer Sample” which is remarkably similar.
The UI thread always has a Synchronization Context, and Synchronization Context.
Raise Can Execute Changed(); } Yes, in the ctor of the View Model, assuming that the ctor is executed on the UI thread.
Can Execute(null); Raise Property Changed("Connection Status"); Raise Property Changed("Discover Expansion Modules Command"); Discover Expansion Modules Command.
WPF is the only XAML framework that uses the Command Manager to automagically raise the Can Execute Changed event on ICommands.
Unfortunately, there is no Command Manager in PCL (portable class library).
I had been merrily using WPF’s built-in support for the Command Pattern for ages (see Commanding Overview, MSDN Docs, and article on implementing the command pattern in WPF, Jeff Druyt)…when suddenly it occured to me that I had no idea By nature of WPF’s awesomeness and WPF Commanding in general, the above Button’s Is Enabled property should automatically be set to true or false based on whether or not the command can or can’t be executed.Speaking of which, let’s set up my Command’s absurd logic in the Code Behind by implementing its Execute and Can Execute event handlers: So, my example is absurd but I bet you see my point by now: WPF is meant to automatically set the Is Enabled Property on that button to true or false, based on the results of the Can Execute method. It seems that when events are raised on the Window (a mouse button click, etc.), Can Execute is re-evaluated.But in this case, the results of Can Execute are a function only of time, and thus change repeatedly and independently of “obvious” application events. (I don’t know the details and wish I did.) But, without further programmatic or user intervention, the button will not automatically change its Is Enabled state once a second.This led me back to the MSDN docs, where I discovered the aptly-named Invalidate Requery Suggested event.To coerce – er, suggest – that WPF should query Can Execute, I set up the following Dispatcher Timer: Now, the Is Enabled property of the Button blinks on and off as the Command’s ability to be executed changes with the passing seconds.