This project has moved and is read-only. For the latest updates, please go here.

CanExecuteChanged event not raised.

May 12, 2010 at 2:41 PM
I'm useing MVVM light toolkit for WPF. It looks like CanExecuteChanged isn't raised at all. Even when I call: RaiseCanExecuteChanged().
May 21, 2010 at 10:25 AM


In WPF, the CanExecute method is called by the CommandManager class. The RaiseCanExecuteChanged method is present in WPF for compatibility with Silverlight, where there is no CommandManager and the CanExecuteChanged event must be raised manually.

In a previous version, I had offered the possibility to force the CanExecuteChanged event to be raised, but it created some issues where the CanExecute method was executed twice. 

Do you have a scenario where the CanExecute method is not called by the CommandManager?



Sep 1, 2010 at 2:59 AM

Actually Laurent I think I'm getting this situation too, a contrived example would be as follows:



            CloseCommand = new RelayCommand(
                () => MessageBox.Show("I don't wanna close! Give up!"),
                () =>
                    if (DateTime.Now.Second % 3 == 0)
                        return true;
                    return false;

            t = new System.Timers.Timer(10);
            t.Elapsed += (s, e) =>

You would imagine that every 10ms it would re-evaluate and update the visual for CloseCommand's bound controls, but this is not the case in WPF.