Xxxweb cam chat rooms - Wpf command canexecute not updating
WPF is the only XAML framework that uses the Command Manager to automagically raise the Can Execute Changed event on ICommands.
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.
Only then did I discover there’s an MSDN Docs sample called “Disable Command Source Via Dispatcher Timer Sample” which is remarkably similar.